Android NDK java.lang.UnsatisfiedLinkError: findLi

2020-01-27 02:29发布

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?

16条回答
唯我独甜
2楼-- · 2020-01-27 03:00

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:

lib -> /mismatched_uid/settings_10037/fs_1000

probably i accidently switched the sharedUserId and thus the library can't be accessed anymore.

查看更多
爱情/是我丢掉的垃圾
3楼-- · 2020-01-27 03:01

If you have a native project with LOCAL_MODULE "libXYZ", make sure to load it as

System.loadLibrary("XYZ");
查看更多
成全新的幸福
4楼-- · 2020-01-27 03:01

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.

查看更多
何必那么认真
5楼-- · 2020-01-27 03:01

I was having the same issue and these are some of the problems I had with my project:


  1. Changing from System.load("hello-test"); into System.loadLibrary("hello-test");;
  2. Changing the C function signature to JNIEXPORT jstring Java_com_example_testndk_TestNDK_funcNami(JNIEnv* env, jobject thiz): here you use Java_<java_package_name>_<java-class-name>_<function-name>;
  3. Adding NDK path to local.properties, in my case ndk.dir=<my-path-to-ndk-directory>; and
  4. Updating my build.gradle to also include within defaultConfig: ndk { moduleName "hello-test" }.

  • Package name: com.example.testndk
  • Java class name: TestNDK
  • C source name: hello-test.c
  • JNI directory location within the project structure: AndroidProjects/TestNDK/app/src/main/jni

IDE: Android Studio 0.8.1.

查看更多
▲ chillily
6楼-- · 2020-01-27 03:02

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:

APP_ABI := all

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.

查看更多
相关推荐>>
7楼-- · 2020-01-27 03:03

UnsatisfiedLinkerror is solved by this.Build your .so file again by "ndk_build"

查看更多
登录 后发表回答