JLT JLT - 1 year ago 353
Android Question

Android - java.lang.UnsatisfiedLinkError: Native method not found

IDE: Android Studio

I have the static library located under the "jniLibs" folder.

enter image description here

I also loaded that library. Here is the code I used:


The native methods were declared on a separate class(ElianNative) as:

public native int InitSmartConnection(String paramString, int paramInt1, int paramInt2);

public native int StartSmartConnection(String paramString1, String paramString2, String paramString3, byte paramByte);

However when I called the method
the app crashed and the error was:

java.lang.UnsatisfiedLinkError: Native method not found: com.monitor.camera.connect.ElianNative.InitSmartConnection:(Ljava/lang/String;II)I

at com.monitor.camera.connect.ElianNative.InitSmartConnection(Native Method)

I don't know the possible cause of this because I just copied this library from another WORKING project and then did the same thing on declaring the methods and importing the necessary headers.

What can be the possible cause of such problem? I searched on stack, some say that it's the absence of Java keyword before the method in the .c file. However I don't think that this can be the problem because like what I said, this is used in another project which is working fine.

Answer Source

If you have copied native library binary files (.so) from other project you must ensure that:

  • declarations of native methods in java are still the same, i.e. both method name and signature remain unchanged
  • declarations of native methods are placed in the class with the same name and package as in donor project.

Also check that System.loadLibrary() ends successfully, without error logs in logcat.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download