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?
just had a similar problem.
Check out your /data/data/your.package.name/lib directory
When i ls in my package directory it currently displays:
probably i accidently switched the sharedUserId and thus the library can't be accessed anymore.
If you have a native project with LOCAL_MODULE "libXYZ", make sure to load it as
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");
intoSystem.loadLibrary("hello-test");
;JNIEXPORT jstring Java_com_example_testndk_TestNDK_funcNami(JNIEnv* env, jobject thiz)
: here you useJava_<java_package_name>_<java-class-name>_<function-name>
;local.properties
, in my casendk.dir=<my-path-to-ndk-directory>
; andbuild.gradle
to also include withindefaultConfig
:ndk { moduleName "hello-test" }
.com.example.testndk
TestNDK
hello-test.c
AndroidProjects/TestNDK/app/src/main/jni
IDE: Android Studio 0.8.1.
None of the previous answers solved my problem, but this did: All along the problem was that a necessary subdirectory and file were not present. All I had in my libs folder was an armeabi folder containing the proper .so file, but there are supposed to be 3 others, each with a .so file in them. Not certain yet which of the other three (armeabi-v7a, mips, or x86) was the required one, but I do know that all three were automatically generated when I added the Application.mk file to the same folder as the Android.mk file, and made sure it had the following line in it:
For me, that line is the only text in there. When ndk-build is then run the Application.mk file apparently causes "all" the 4 folders to be created and the proper .so files to be created in them. Once I got Application.mk in place, I ran ndk-build again, and then did a clean and a clear on my Eclipse project before trying again. Everything ran perfectly.
UnsatisfiedLinkerror is solved by this.Build your .so file again by "ndk_build"