简体   繁体   English

Eclipse错误“找不到java.lang.unsatisfiedlinkerror本机方法”

[英]Eclipse Error “java.lang.unsatisfiedlinkerror Native method not found”

I am developing Android project thru Eclipse Luna + APK19 + ndk_r10b. 我正在通过Eclipse Luna + APK19 + ndk_r10b开发Android项目。 I try to pick up NDK development flow thru some online tutorial. 我尝试通过一些在线教程来了解NDK的开发流程。 http://www.decom.ufop.br/imobilis/?p=1832 http://www.decom.ufop.br/imobilis/?p=1832

I able to compile in Eclipse without error, but when I run to virtual device, it pop-up the Error "java.lang.unsatisfiedlinkerror Native method not found", then the virtual device show "Unexpected Stop". 我能够在Eclipse中编译而没有错误,但是当我运行虚拟设备时,它会弹出错误“ java.lang.unsatisfiedlinkerror Native method not found”,然后虚拟设备显示“ Unexpected Stop”。 I try to export as .apk, it fail on hardware as well. 我尝试导出为.apk,它在硬件上也失败。 I try to changes different tutorial, but same problem show up. 我尝试更改不同的教程,但出现相同的问题。

Can help to show me some light on how to debug? 可以帮助我了解如何调试吗? I have stuck at here more than a week, very appreciate the help. 我在这里停留了一个多星期,非常感谢您的帮助。 Thanks in advanced. 提前致谢。

09-30 03:07:15.668: I/Process(1723): Sending signal. PID: 1723 SIG: 9
09-30 03:29:02.248: D/dalvikvm(1770): Trying to load lib /data/app-lib/com.test.ndkexample-
2/libNativeFunctionality.so 0xb4d45338
09-30 03:29:02.248: D/dalvikvm(1770): Added shared lib /data/app-lib/com.test.ndkexample 2/libNativeFunctionality.so 0xb4d45338
09-30 03:29:02.248: D/dalvikvm(1770): No JNI_OnLoad found in /data/app-lib/com.test.ndkexample ibNativeFunctionality.so 0xb4d45338, skipping init
09-30 03:29:02.568: W/dalvikvm(1770): No implementation found for native Lcom/test/ndkexample/MainActivity;.HelloWorldNDK:()V
09-30 03:29:02.568: D/AndroidRuntime(1770): Shutting down VM
09-30 03:29:02.568: W/dalvikvm(1770): threadid=1: thread exiting with uncaught exception (group=0xb4a94ba8)
09-30 03:29:02.578: E/AndroidRuntime(1770): FATAL EXCEPTION: main
09-30 03:29:02.578: E/AndroidRuntime(1770): Process: com.test.ndkexample, PID: 1770
09-30 03:29:02.578: E/AndroidRuntime(1770): java.lang.UnsatisfiedLinkError: Native method not found: com.test.ndkexample.MainActivity.HelloWorldNDK:()V
09-30 03:29:02.578: E/AndroidRuntime(1770):     at com.test.ndkexample.MainActivity.onStart(MainActivity.java:34)
09-30 03:29:02.578: E/AndroidRuntime(1770):     at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1171)
09-30 03:29:02.578: E/AndroidRuntime(1770):     at android.app.Activity.performStart(Activity.java:5241)
09-30 03:29:02.578: E/AndroidRuntime(1770):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2168)
09-30 03:29:02.578: E/AndroidRuntime(1770):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
09-30 03:29:02.578: E/AndroidRuntime(1770):     at android.app.ActivityThread.access$800(ActivityThread.java:135)
09-30 03:29:02.578: E/AndroidRuntime(1770):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
09-30 03:29:02.578: E/AndroidRuntime(1770):     at android.os.Handler.dispatchMessage(Handler.java:102)
09-30 03:29:02.578: E/AndroidRuntime(1770):     at android.os.Looper.loop(Looper.java:136)
09-30 03:29:02.578: E/AndroidRuntime(1770):     at android.app.ActivityThread.main(ActivityThread.java:5017)
09-30 03:29:02.578: E/AndroidRuntime(1770):     at java.lang.reflect.Method.invokeNative(Native Method)
09-30 03:29:02.578: E/AndroidRuntime(1770):     at java.lang.reflect.Method.invoke(Method.java:515)
09-30 03:29:02.578: E/AndroidRuntime(1770):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
09-30 03:29:02.578: E/AndroidRuntime(1770):     at     com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
09-30 03:29:02.578: E/AndroidRuntime(1770):     at dalvik.system.NativeStart.main(Native Method)

MainActivity.java MainActivity.java

package com.test.ndkexample;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;

public class MainActivity extends ActionBarActivity {

    static {
        System.loadLibrary("NativeFunctionality");
        }

    TextView ndkTextView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {    
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
    }

    @Override
    protected void onStart() {
    super.onStart();
    HelloWorldNDK();
    ndkTextView = (TextView)findViewById(R.id.ndkText);
    String ndkString = GetAnswer();
    ndkTextView.setText(ndkString);
    }


    public native void HelloWorldNDK();
    public native String GetAnswer();
    }  

NativeFunctionality.cpp NativeFunctionality.cpp

#include <jni.h>
#include "NativeFunctionality.h"
#include <android/log.h>
#include <pthread.h>
#include <unistd.h>
#define LOG_TAG "NDKTest"

JNIEXPORT void JNICALL Java_com_test_NDKExample_MainActivity_HelloWorldNDK
(JNIEnv *env, jobject obj)
{
__android_log_print(ANDROID_LOG_INFO,LOG_TAG,"Native function called!");

return;

}

JNIEXPORT jstring JNICALL Java_com_test_NDKExample_MainActivity_GetAnswer
(JNIEnv *env, jobject obj)

{

    return (env->NewStringUTF("String returned from native environment!"));

}

NativeFunctionality.h NativeFunctionality.h

/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class com_test_ndkexample_MainActivity */

#ifndef _Included_com_test_ndkexample_MainActivity
#define _Included_com_test_ndkexample_MainActivity
 #ifdef __cplusplus

extern "C" {

#endif
/*
 * Class:     com_test_ndkexample_MainActivity
 * Method:    HelloWorldNDK
 * Signature: ()V
     */
JNIEXPORT void JNICALL Java_com_test_ndkexample_MainActivity_HelloWorldNDK
  (JNIEnv *, jobject);

 /*
 * Class:     com_test_ndkexample_MainActivity
 * Method:    GetAnswer
 * Signature: ()Ljava/lang/String;
 */
JNIEXPORT jstring JNICALL Java_com_test_ndkexample_MainActivity_GetAnswer
  (JNIEnv *, jobject);

#ifdef __cplusplus

}
#endif
#endif

Android.mk Android.mk

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog
LOCAL_MODULE    := NativeFunctionality
LOCAL_SRC_FILES := NativeFunctionality.cpp

include $(BUILD_SHARED_LIBRARY)
JNIEXPORT void JNICALL Java_com_test_NDKExample_MainActivity_HelloWorldNDK(JNIEnv *env, jobject obj)

Is incorrect. 是不正确的。 Your function name must exactly match your native method declaration, including capitalization (or not) of the package name. 您的函数名称必须与您的本机方法声明完全匹配, 包括程序包名称的大写 (或不包括 )。

package com.test.ndkexample;
public class MainActivity extends ActionBarActivity {
    public native void HelloWorldNDK();
}

requires 要求

JNIEXPORT void JNICALL Java_com_test_ndkexample_MainActivity_HelloWorldNDK(JNIEnv *env, jobject obj)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.lang.UnsatisfiedLinkError:在运行时调用本机方法Eclipse时找不到本机方法 - java.lang.UnsatisfiedLinkError: Native method not found while runtime call for that native method Eclipse linphone android登录错误java.lang.UnsatisfiedLinkError:找不到本机方法 - linphone android login error java.lang.UnsatisfiedLinkError: Native method not found eclipse:java.lang.UnsatisfiedLinkError - eclipse: java.lang.UnsatisfiedLinkError java.lang.UnsatisfiedLinkError:找不到本机方法:org.cocos2dx.lib.Cocos2dxHelper.nativeSetApkPath: - java.lang.UnsatisfiedLinkError: Native method not found: org.cocos2dx.lib.Cocos2dxHelper.nativeSetApkPath: Android java.lang.UnsatisfiedLinkError-nativeLibraryDirectories(Eclipse) - Android java.lang.UnsatisfiedLinkError - nativeLibraryDirectories (Eclipse) Eclipse中的OpenCV 3.0.0 java.lang.UnsatisfiedLinkError - OpenCV 3.0.0 java.lang.UnsatisfiedLinkError in Eclipse OpenCV 4.3.0 java.lang.UnsatisfiedLinkError 在 Eclipse - OpenCV 4.3.0 java.lang.UnsatisfiedLinkError in Eclipse ADB中的java.lang.UnsatisfiedLinkError和未知错误 - java.lang.UnsatisfiedLinkError and unknown error in ADB ECLIPSE-使用JNI时出现java.lang.UnsatisfiedLinkError - ECLIPSE - java.lang.UnsatisfiedLinkError while working with JNI Cocos2D-x Eclipse java.lang.UnsatisfiedLinkError - Cocos2D-x Eclipse java.lang.UnsatisfiedLinkError
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM