I've wrote android app with native shared library ( libnativeext.so ).
Inside java class in app I load libnativeext.so with System.loadLibrary("nativeext"). All works great. Native code compiles, and libnativeext.so places in /libs/armeabi/ folder. So final first.apk file contains /lib/armeabi/libnativeext.so, installs on device and all work ok.
Then I export project in javaext.jar.
At this point javaext.jar contains libnativeext.so in /libs/armeabi/.
In the new project (second-proj) I include javaext.jar and add path to javaext.jar in java build path. Project builds with only warning about native library in javaext.jar. I disable warning in eclipse preferences.
But on device I got: java.lang.UnsatisfiedLinkError: Couldn't load nativeext: findLibrary returned null
Strange, because second.apk have /libs/armeabi/libnativeext.so inside. I go to phone and figure out than folder on phone /data/data/myapp/lib/ is EMPTY! And ofcourse System.loadLibrary can't find libnativeext.so.
I find solution for myself, but it looks very ugly, and I want to find better way.
I create inside existing second-proj/libs/ folder armeabi and place libnativeext.so inside.
second-proj:
/libs/armeabi/libnativeext.so
/libs/javaext.jar
When I build project, I look inside second.apk:
/lib/armeabi/libnativeext.so <--- new one
/libs/armeabi/libnativeext.so
And this version work perfect on the phone.
So I assume, that during installation libraries from /libs/armeabi/ is ignored, and only libraries from /lib/armeabi/ is installed on the phone.
So question is: How to force apk bulder to copy *.so from *.jar to right *.apk folder?
In case there are no way to pack *.so library from included *.jar into final *.apk I solve this problem for myself.
I write LibraryLoader, which:
Tries to load library with System.loadLibrary().
If it fails, loader search library in application storage, and if find loads it with System.load().
If no library was found in the app storage, it find .apk file, serch there, and if loader find library - copies it to app storage, then loads it with System.load().
Post code here - may be it helps somebody.