Search code examples
androidandroid-ndknullnativeunsatisfiedlinkerror

Why won't my native library load in my Android App?


I have placed a .so library within the /libs/armeabi/ folder(I also tried just within the /libs folder) of my app and then tried loading with a static method. I am am getting an UnsatisfiedLinkError/null error.

I have tried the full path within the static method but I still get the error.

static {
    System.loadLibrary("/data/data/com.imtroymiller.myapp/lib/armeabi/libmylib.so");
}

This is the full error message that I receive.

    08-04 12:49:22.204: E/AndroidRuntime(3352): java.lang.UnsatisfiedLinkError: Couldn't load /data/data/com.imtroymiller.myapp/lib/armeabi/libmylib.so from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.imtroymiller.myapp-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.imtroymiller.myapp-1, /vendor/lib, /system/lib]]]: findLibrary returned null

I have read through the tutorial below and I understand how to used to NDK to create a library from source code, but I am trying to load an existing library into my app so that I can run an executable that depends on the library.

http://code.tutsplus.com/tutorials/ndk-tutorial--mobile-2152

I've tried this on two devices, both have root access. One is CyanogenMod 11 and the other is CyanogenMod 12.

Edit: I was able to load them using...

System.load("/data/data/com.imtroymiller.myapp/lib/libmylib.so");

It looks like System.load takes the path name and System.loadLibrary takes the library name. But both with load the library.


Solution

  • I was able to load them using...

    System.load("/data/data/com.imtroymiller.myapp/lib/libmylib.so");
    

    It looks like System.load takes the path name and System.loadLibrary takes the library name. But both will load the library.