简体   繁体   中英

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

IDE: Android Studio

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

在此处输入图片说明

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

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

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 InitSmartConnection 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.

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, ie 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM