0

I'm new in using native methods for Android. I got the errors as below even after I have make sure my armeabi, armeabi-v7a, mips and x86 with correct *.so file are put correctly in the folders.

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)

As below is how I loaded my .so file:

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

Something extra (which I don't think that's the main issue)?

In the same file where I load my library, I have this method:

public static native void MIMAS_LoadModel(int ppModel);

Main 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");

Kindly please help me with that. Thanks in advance!

polkaspot01
  • 33
  • 1
  • 10

1 Answers1

0
  1. loadLibrary() takes the name without "lib" prefix.

  2. If you don't use RegisterNatives(), you should name the exported functions of your native library according to javah prescriptions, e.g. Java_com_arzap_mimas_MimasJNI_MIMAS_1LoadModel.

  3. If the native code is C++, make sure the exported functions have extern "C" prefix to pervent name mangling.

Alex Cohn
  • 56,089
  • 9
  • 113
  • 307
  • Unfortunately, I don't understand your question. The message in your Q shows that the native library was loaded (unlike the problem in the [referenced Q](http://stackoverflow.com/questions/27421134/system-loadlibrary-couldnt-find-native-library-in-my-case)). Actually, you should see an explicit line in logcat about library loaded. If you are using a 3rd party shared lib, and write a Java layer for it, note that your Java class and package should match exactly the names in the shared lib. – Alex Cohn Oct 22 '15 at 06:51
  • You have a tool called [`nm`](http://stackoverflow.com/a/23124518/192373) in NDK. Please run `nm -D /libMimasAr3D.so` and see how exactly the native methods are named there. – Alex Cohn Oct 22 '15 at 08:24
  • It's exactly the same name libMimasAr3D.so, I even tried to put in the dependencies in *.so(no effect as well). That's why I'm here asking for the expert and get help with this. – polkaspot01 Oct 22 '15 at 08:41
  • So, what is the answer of `nm -D`? – Alex Cohn Oct 22 '15 at 08:59
  • Thousand lines is OK, can you find your native methods among them? – Alex Cohn Oct 22 '15 at 11:11