UnsatisfiedLinkError:找不到.so文件正确放入Eclipse库

时间:2015-10-21 11:05:54

标签: android opencv java-native-interface shared-libraries native

我是使用Android原生方法的新手。即使我确保我的armeabi,armeabi-v7a,mips和带有正确* .so文件的x86正确放入文件夹中,我也得到了如下错误。

10-21 18:51:36.685: E/AndroidRuntime(24277): java.lang.UnsatisfiedLinkError: Native method not found: com.arzap.mimas.MimasJNI.MIMAS_LoadModel:(Ljava/lang/String;)V
10-21 18:51:36.685: E/AndroidRuntime(24277):    at com.arzap.mimas.MimasJNI.MIMAS_LoadModel(Native Method)
10-21 18:51:36.685: E/AndroidRuntime(24277):    at com.arzap.mimas.ar.MainActivity.onCreate(MainActivity.java:36)
10-21 18:51:36.685: E/AndroidRuntime(24277):    at android.app.Activity.performCreate(Activity.java:5451)
10-21 18:51:36.685: E/AndroidRuntime(24277):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
10-21 18:51:36.685: E/AndroidRuntime(24277):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2377)
10-21 18:51:36.685: E/AndroidRuntime(24277):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2471)
10-21 18:51:36.685: E/AndroidRuntime(24277):    at android.app.ActivityThread.access$900(ActivityThread.java:175)
10-21 18:51:36.685: E/AndroidRuntime(24277):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
10-21 18:51:36.685: E/AndroidRuntime(24277):    at android.os.Handler.dispatchMessage(Handler.java:102)
10-21 18:51:36.685: E/AndroidRuntime(24277):    at android.os.Looper.loop(Looper.java:146)
10-21 18:51:36.685: E/AndroidRuntime(24277):    at android.app.ActivityThread.main(ActivityThread.java:5602)
10-21 18:51:36.685: E/AndroidRuntime(24277):    at java.lang.reflect.Method.invokeNative(Native Method)
10-21 18:51:36.685: E/AndroidRuntime(24277):    at java.lang.reflect.Method.invoke(Method.java:515)
10-21 18:51:36.685: E/AndroidRuntime(24277):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
10-21 18:51:36.685: E/AndroidRuntime(24277):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
10-21 18:51:36.685: E/AndroidRuntime(24277):    at dalvik.system.NativeStart.main(Native Method)

以下是我加载.so文件的方式:

static{
    try {
        System.loadLibrary("libMimasAr3D");
    } catch (UnsatisfiedLinkError use) {
        Log.e("JNI", "WARNING: Could not load libMimasAr3D.so");
    }
}

额外的东西(我不认为这是主要问题)?

在我加载库的同一文件中,我有这个方法:

public static native void MIMAS_LoadModel(int ppModel);

主要Activity.java:

   //Description: Load the model.
   //Input: pModelPath - A file path to the saved model.
   //Return: A pointer to the object of the model. NULL if loading is failed.
    //Load image to MIMAS_SDK
    MimasJNI.MIMAS_LoadModel("models/model.bin");

请帮助我。提前谢谢!

1 个答案:

答案 0 :(得分:0)

  1. loadLibrary()使用不带 "lib" 前缀的名称。

  2. 如果您不使用RegisterNatives(),则应根据javah处方命名原生图书馆的导出功能,例如Java_com_arzap_mimas_MimasJNI_MIMAS_1LoadModel

  3. 如果本机代码是C ++,请确保导出的函数具有 extern "C" 前缀以防止名称重整。