8

I successfully cross-compiled a c++ library with the android ndk-Standalone toolchain then, i created a new android application project into Eclipse and when i put mylib.so into the jni folder and execute ndk-build commands it works fine

Prebuilt       : mylib.so <= jni/
Install        : mylib.so => libs/armeabi/mylib.so

But when adding

static{
  System.load("/data/data/my_package/lib/mylib.so");
}

i got an error in the logcat saying

   AndroidRuntime
   Caused by: java.lang.UnsatisfiedLinkError: Cannot load library:
   reloc_library[1306]:      36 cannot locate 'xmlCleanupParser'...``

i googled it but didn't find any way to solve this problem.

Lukas Knuth
  • 25,449
  • 15
  • 83
  • 111
Hadj Ali Oussama
  • 784
  • 2
  • 8
  • 29

5 Answers5

11

People mostly forgot cut "lib" prefix form library name. So if you have "libusb.so" your code must be System.loadLibrary("usb")...

cevdet
  • 111
  • 1
  • 3
6

I recently encountered the same error. After trying out dozens of suggestions from SO, I finally figured out that the error was in my native code. even though android ndk had compiled it without any issues / warnings.

Try writing a simple main function to test your native code and compile with g++/gcc (or something similar) to check for errors.

I know its too late for the asker, but hope someone else finds this useful.

5

If you have your compiled native library (the .so-file) in your lib/-directory, you can refer to it without using the full path:

static{
  System.load("mylib");
}

As shown in the tutorial.


Check to see if you set the right package in your Header-file: How to resolve the java.lang.UnsatisfiedLinkError in NDK in Android?

Community
  • 1
  • 1
Lukas Knuth
  • 25,449
  • 15
  • 83
  • 111
4
try {
       System.load("/data/data/<package name>/lib/libsample-jni.so");
    } catch (UnsatisfiedLinkError e) {
       System.loadLibrary("<sample-jni>"); //remove lib and .so from name
}

this will help you, Pls. check.

Desu
  • 464
  • 4
  • 6
2

Please specify your .so file like as follow.

 static {

     System.loadLibrary("mylib");

}

Hope this will help you.

itsrajesh4uguys
  • 4,610
  • 3
  • 20
  • 31