Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to dlopen(libsomething.so) Cannot load library: link_image[1995]: failed to link libsomething.so

I am writing an android project which has Native layer helping the java layer, and am stuck at a place where when i try to do a System.loadLibrary, it is throwing error that it is not able to link it.

I am using Target specific NDK to build the native layer, and then using ant to compile and create the apk.

On running on the device i get the following error.

Unable to dlopen(libsomething.so) Cannot load library: link_image[1995]: failed to link libsomething.so

The library get bundled into the apk, and is unpacked properly. If i try to remove the library manually and then run it, it then actually throws that library not found. So it is able to find the library, but it throws this error, and i am not able to find out why this error is coming.

Please help me.

like image 496
Puneet Avatar asked Jan 18 '11 11:01

Puneet


4 Answers

First find the location of the .so file. and then can try:

Following example assumes the location of shared library as: /data/data/my.package/lib/libmysharedlibrary.so

try {
    //System.loadLibrary("mysharedlibrary");
    System.load("/data/data/my.package/lib/libmysharedlibrary.so");
} catch (UnsatisfiedLinkError use) {
    Log.e("JNI", "WARNING: Could not load libmysharedlibrary.so");
}
like image 195
TheCottonSilk Avatar answered Oct 16 '22 08:10

TheCottonSilk


I've trap in the same question. finally I got answer from this article: http://mpigulski.blogspot.com/2010/09/debugging-dlopen-unsatisfiedlinkerror.html

use

arm-linux-androideabi-readelf.exe  -d libs/armeabi/libmy.so

Then Found a NEEDED Shared library in wrong name.

like image 23
g00g1e Avatar answered Oct 16 '22 07:10

g00g1e


Sometimes (most of the time!) you library requires other libraries as mentioned by @musefan. and you can list them doing readelf -d libs/armeabi/libmy.so. However there is a catch here: since Android has no any mechanism to control library version (like in normal linux you have liblzma.so.1, liblzma.so.2, etc) the library you need is there (liblzma.so) BUT has no some symbols imported by your library. Here is the live example: you use android::ZipFileRO::getEntryInfo function located in libutils.so. All version of the library has this function however the PROTOTYPE of the function has been changed at the end of 2010 so you app built for 4.0.4 NDK will not run on FroYo devices or GB devices with the same symptomatic: dlopen cannot load library. Here is the recipe how to detect such cases: you need the contents os /system/lib folder on your PC. It may be folder dumped from your device if you are 3rd party App developed or built if you are platform developer. then issue the command arm-linux-gnueabi-ld -rpath-link /path/to/system/lib ./lib_mylib.so and you will see something lie this in case of error
lib_mylib.so: undefined reference toandroid::ZipFileRO::getEntryInfo(void*, int*, long*, long*, long*, long*, long*) const'`

like image 42
mishmashru Avatar answered Oct 16 '22 09:10

mishmashru


You can also find this error while using calling System.load(String pathName) method and just passing libraryName instead of complete path to library.

Resolution : use System.loadLibrary(String libName) method and now pass the libraryName.

like image 3
Napolean Avatar answered Oct 16 '22 09:10

Napolean