Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android NDK library: findLibrary returned null

I'm trying to build a medium-size project in Eclipse. It consists of main app project and two Android libraries. Everything worked fine until I added a very simple JNI library to main project.

When I run the app on device I see this exception in LogCat:

01-11 17:19:01.421: E/AndroidRuntime(26569):at java.lang.Runtime.loadLibrary(Runtime.java:429) Couldn't load xxx: findLibrary returned null

I googled around for similar problems and I believe that I did everything correctly:

  1. The only .c file and Android.mk file are placed in the 'jni' folder
  2. I build the library with ndk-build tool
  3. The .so library is correctly placed in the 'libs\armeabi' folder
  4. I see that the resulting apk file does indeed contain my native library

When I create a test project and link to the very same native code - it works fine. The problem persists in the main project. I already tried to create Eclipse project from scratch but it didn't help

I use Android SDK Tools v.16

Can anyone please help me with a suggestion?

Thanks!

like image 414
Anton Avatar asked Oct 10 '22 00:10

Anton


1 Answers

Ok, after two days fighting the Android SDK I managed to solve my problem. Here's some explanation just in case it may help anybody else.

My previous project structure:

  1. Android Lib1 project (with it's own jni code)
  2. Android Lib2 project (depends on Lib1)
  3. App1 project (depends on Lib2)
  4. App2 project (with it's own jni code; depends on Lib2)

The original problem has been seen when I tried to load jni library in App2. I still don't understand what was preventing the runtime from finding the jni in the App2.

However the solution was to remove the Lib1 project from the workspace and add it as JAR file to Lib2 and both Apps. Now I'm finally able to use load the jni lib in the App2.

like image 171
Anton Avatar answered Oct 13 '22 10:10

Anton