Android NDK Error:java.lang.UnsatisfiedLinkError: Couldn’t load XXX indLibrary returned null

Android Studio shows following error

5-31 18:45:52.320  10741-10741/com.example.hellojni E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.example.hellojni, PID: 10741
    java.lang.UnsatisfiedLinkError: Couldn't load hello-jni from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.example.hellojni-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.hellojni-1, /vendor/lib, /system/lib]]]: findLibrary returned null
            at java.lang.Runtime.loadLibrary(Runtime.java:358)
            at java.lang.System.loadLibrary(System.java:526)
            at com.example.hellojni.HelloJni.<clinit>(HelloJni.java:64)
            at java.lang.Class.newInstanceImpl(Native Method)
            at java.lang.Class.newInstance(Class.java:1208)
            at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2107)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2239)
            at android.app.ActivityThread.access$800(ActivityThread.java:141)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1202)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5047)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
            at dalvik.system.NativeStart.main(Native Method)

Maybe you didn’t add platform support in the Application.mk or they are not compiled correctly.

Solution1:

Default ANdroid JNI Folder is set like this

//Structure has to be like following
|---src
     |---main
           |---jniLibs
                  |---arm64-v8a
                         |---libhello-jni.so
                  |---armeabi
                         |---libhello-jni.so
                  |---armeabi-v7a
                         |---libhello-jni.so
                  |---x86
                         |---libhello-jni.so
                  |---x86_64
                         |---libhello-jni.so
                  |---mips
                         |---libhello-jni.so
                  |---mips64
                         |---libhello-jni.so

The Structure has to be like this, if you don’t get it, go to | Android Studio 添加动态库os文件的方法 (Yes, it’s in Chinese)

Solution2(Recommended)

Modify build.gradle as follow

android {
    sourceSets {
        main {
            jniLibs.srcDirs = ['libs']
        }
}
PS.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s