Android Unable to load '.so.1' file

754 views Asked by At

Hi I am working on a Android native application.

There is 'abc.so' files which depend on some 'xyz.so.1' file. All of the required files are available in the project structure before building, but the '.so.1' are not a part of the generated .apk file (I checked the apk file by unpacking).

This is causing in a "'java.lang.UnsatisfiedLinkError' Couldnt load 'abc.so.1' from loader dalvik" when trying to run the application.

I dont want to push the .so.1 file as the phone is not rooted and runs on a production build. How do I include the .so.1 files as a part of the APK?

Thank you.

1

There are 1 answers

0
Shrish On BEST ANSWER

I think you havent got the concept of loading native libraries to Java through JNI.

First you define the native methods in java and do the corresponding implementation in the native and compile it (you have to register the native methods by either 1) following a naming convention 2) registering the native methods in jni_onload...i think you must have done this, if not check http://www.ntu.edu.sg/home/ehchua/programming/android/android_ndk.html)

Next, you have to load the library before any call can be made to native. This has to be done once. You can do it in an activity by defining:

static{

System.loadLibrary("mylib.so");

}

Note while compiling the library you will have got the library name as libXYZ.so, but when loading the library in java the "lib" should be omitted ,just system.loadlibrary(XYZ.so) If you are using NDK the library would have been already copied to Java project > libs > armeabi folder , if not you have to copy your lib.so there

Now if you have multiple shared libraries , you should load the least dependent lib.so first , followed by second etc i.e.

Static {

System.loadLibrary(independent_lib.so); // should depend on only android libs System.loadLibrary(next_dependent_lib1.so); //can depend on android libs and independent_lib.so System.loadLibrary(next_dependent_lib2.so); //can depend on android libs,independent_lib.so,next_dependent_lib1.so ..... .... ..

}

If you jumble up, the VM will not be able to link the libraries and throw a unsatisfied link error.

Lastly, all this .so s will be part of your apk and it will be pushed to the system libs only runtime. Unless its a rooted phone you cannot extract the .so. If you follow the above method you will not need to push any .so to the system. Only build on eclipse/cygwin and run

Hope this helps,

Regards, Shrish