Having the above error in your Android JNI app? Read on...
Up front, I'll say that I've already solved this, in my own way, but I feel something in the Android build system (perhaps regarding Eclipse) is broke, and I hope to save someone else hours of pain. Perhaps others have come across this issue and can comment on what worked for them.
For a while, I've had an Android project with some JNI code that I developed using the NDK. Then, today, I changed something in the java code and then poof, I could no longer load my JNI library. It failed with an exception like:
E/AndroidRuntime( 999): java.lang.UnsatisfiedLinkError: Couldn't load mylibrary: findLibrary returned null
I googled and tried everything (rebuilding, close and relaunch Eclipse, etc, etc)
What finally fixed my problem? I physically uninstalled my app from the device before trying another run. That's it. After that, it worked. What worked for you?
If you have a native project with LOCAL_MODULE "libXYZ", make sure to load it as
System.loadLibrary("XYZ");
If you are trying to run your app in a simulator, then make sure that you have specified the correct architecture in Run -> Run Configurations -> Target (you may need to add the required simulator using Window -> Android Virtual Device Manager).
I had the same problem when trying to execute an app in an Intel simulator, while the app was using a library precompiled for the ARM.
I've got this issue too, but for my situation, i'm using my libs in another project. And I don't think it's a matter of eclipse or android-ndk.
you may check these tips that can lead to UnsatisfiedLinkError
and it works fine for me, good luck :)
/your project/libs/armeabi/
EDIT:
UnsatisfiedLinkError
are thrown if the library is not installed into your app.apk, so it cannot be linked sucessfully.In my case, while making a System Application the issue was related to permissions. After putting the ".so" files into /system/lib/
or /system/vendor/lib/
directory, I modified the default allocated permissions 600 to 755. It worked well.
Inside libs folder, I create a new folder called armeabi-v7a, and copied the .so file from armeabi to the new folder. It solves the error.
I was having the same issue and these are some of the problems I had with my project:
System.load("hello-test");
into System.loadLibrary("hello-test");
;JNIEXPORT jstring Java_com_example_testndk_TestNDK_funcNami(JNIEnv* env, jobject thiz)
: here you use Java_<java_package_name>_<java-class-name>_<function-name>
;local.properties
, in my case ndk.dir=<my-path-to-ndk-directory>
; andbuild.gradle
to also include within defaultConfig
: ndk { moduleName "hello-test" }
.com.example.testndk
TestNDK
hello-test.c
AndroidProjects/TestNDK/app/src/main/jni
IDE: Android Studio 0.8.1.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With