Reputation: 1880
I'm having some troubles about using a shared library (.so) in an Android application. I have 3 projects:
Native code project => build c++ files in .so library Let's call it libNative.so
Android library project => calls the native code. The output of this project is a .jar file. Let's call it "stack.jar"
Android application sample which uses the android library project.
In the sample application (3) libraries' properties tab, I configured the stack.jar file to be linked with the .so library. My .so native library is well included in the generated APK. => Eclipse copies it in the "lib/armeabi" folder.
If I launch the APK on a phone, I get the following error:
Caused by: java.lang.UnsatisfiedLinkError: Couldn't load libNative:
findLibrary returned null at
java.lang.Runtime.loadLibrary(Runtime.java:365) at
java.lang.System.loadLibrary(System.java:535)
I'm guessing the error is that Eclipse copies the .so library in a lib folder instead of libs , and that System.loadLibrary is looking for the path libs/armeabi..., right ? Or I may be totally wrong !
Thanks a lot for your help,
EDIT: when I install the APK, the .so lib is well copied in data/data/mypackage/lib folder. Still, I can't load it. Is it because the load is happening in the .jar file and not directly in the application sample ??
Upvotes: 3
Views: 7321
Reputation: 1880
According you have generated a dynamic library called libExample.so
Write in a class the following code as fadden said:
try
{
System.loadLibrary("Example");
}
catch (UnsatisfiedLinkError use)
{
Log.e("JNI", "WARNING: Could not load native library");
}
Should work !
Upvotes: 4