Android NDK library: findLibrary returned null - android

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:
The only .c file and Android.mk file are placed in the 'jni' folder
I build the library with ndk-build tool
The .so library is correctly placed in the 'libs\armeabi' folder
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!

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:
Android Lib1 project (with it's own jni code)
Android Lib2 project (depends on Lib1)
App1 project (depends on Lib2)
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.

Related

JNI folder is not picked up by Android studio after headers are generated

I am working on building an Android Library which is part of a larger Android app project. I am using Android Studio.
I created the Android library as a module in the Android app project. I created my native methods, and then I put the .class through javah -jni and I was able to see the jni folder created and the header file generated.
However, Android Studio is not picking up the jni folder and showing it in the project view.
Anybody have any idea, what am I missing?
After hours of looking through docs, and posts, and tutorials, I remembered to check the simplest of things. Make sure your jni folder is in src/main

Including *.so files with gradle and Android Studio 1.2.2

Can someone guide me on the correct placement of where *.so files are supposed to be housed for a gradle/android project?
I have them in:
project->app->src->main->jniLibs
and the assets, java, and res folders are siblings to it in main as well but they don't seem to be included when the APK is built causing an 'UnsatisfiedLinkError'
EDIT
I have looked at:
Include .so library in apk in android studio
and have tried changing the director to both libs and lib with no luck.
UPDATE 1
The APK de-compiled now shows the *.so files under /Lib and I have them under project -> app -> src -> main -> jniLibs -> armeabi and that is their architecture but I am getting an UnsatisfiedLinkError when calling a method from within the native library although it seems to get past the System.loadLibrary call in the static constructor without showing an error
*.so files are included and shown in decompiled APK now...hitting another issue which I posted here: UnsatisfiedLinkError when calling method from native library although System.loadLibrary seems ok

android .so files not getting extracted in /data/data/<package>/lib

I am developing a native android application and using an open source library with .so file generated. Facing a strange behavior.
For the first few times, the application worked perfectly well, with the library getting loaded. But now its not able to find the library and gives -
java.lang.UnsatisfiedLinkError: Couldn't load : findLibrary
returned null
.Below are few observations: 1. when I extract the .apk file, the library (.so) is present under "lib/armeabi" folder. 2. but when I try to search the library (.so) into the devices extracted path of
/data/data//lib/
, its not present. Any suggestions as to why this strange behavior is happening and why the .so file is not getting extracted under /data/data/com.ibm.homeScreen/lib/ folder.
Thanks in advance!
If you use eclipse, check the buildpath settings:
Right click on your project --> Properties --> JavaBuildPath --> Order and Export (is a Tab) and check there if the librar has been marked (checkbox) to export.
There is also a possibility to set the native library path. You can find that option in the Library Tab --> Android Private Libraries --> EDIT Button on the right
This could also help
For eclipse project, simply put all your *.so files inside armeabi or armeabi-v7a folder, and put the folder inside /libs folder in your project. Compile, the *.so files will automatically be imported into /data/data//lib
For Android studio, the above approach didn't work for me. instead I have to place the armeabi and armeabi-v7a folders into /jniLibs instead of /libs. Note that I am using Gradle 0.10.+ though, not sure if it works on older Gradle.
You can find some further information about this problem here:
Why do some Android phones cause our app to throw an java.lang.UnsatisfiedLinkError?
https://code.google.com/p/android/issues/detail?id=59420
The stackoverflow link also contains some code with a workaround in the (currently) last answer.

Import JAR that uses .so files into a new android project

I'm trying to build an app using a library packed in a JAR file.
When I call one of the functions I get this error:
Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing thelibrary.class
I've check the source code of the library and I think it crushes when loading some .so files ( System.loadLibrary("usb-1.0");
those files do exists in the JAR project under libs/armeabi (libusb-1.0.so)
I guess the .so files are not packed with the JAR, so how do I get them to be found in my project ?
(tried to copy them to libs/armeabi but the same exception is thrown....)
I do not get any link / build errors....
Thanks.
An ordinary JAR file will not work for distributing something that is dependent upon an Android NDK-compiled library. However, an Android library project can also distribute an NDK-compiled library.
but the real problem is that my app is going to be a library as well, and I don't know if I can make it a library while it is using other libraries
Assuming that "make it a library" == "make it an Android library project", this is fine, so long as projects attempting to use your library project also have access to the other library project.

I got the error on sample project "Hello Word" on android - cocos2d

I have eclipse 3.7, cocos2d-1.0.1-x-0.9.2, android-ndk-r7.
When I have create sample project but, it will get error "FORCE CLOSE"...
So is there any other thing i want to include on the project ?
Your main application has a load static library method that is pointing to a nonexistent library, which means it has not found it. Recheck your makefiles for the correct module name. Also make sure they have compiled correctly with NDK beforehand and the .a and .so files are in the lib folder.

Categories

Resources