How to add multiple native libraries (.so) files in IntelliJ
Asked Answered
H

1

7

I have two 3rd party native libraries, say libfoo.so and libbar.so. I'm having hard time loading both of these libraries. I've copied them to libs folder under proper CPU arch (armeabi, mips, and x86) as well as set the Native libs directory under Project Structure>Modules>Android>Structure to point to this libs folder. I can only load one library but not the other. If I try to load them one at a time (deleting the other libraries), it runs fine. The exception that I'm getting is:

java.lang.UnsatisfiedLinkError: Couldn't load foo from loader dalvik.system.PathClassLoader 

What should I do to have IntelliJ or Android runtime to find both these native libraries?

Histrionism answered 3/3, 2013 at 8:17 Comment(3)
How did you load them?Colleencollege
Did you look in the resulting .APK file to see what gets placed there? It's just a zip file -- open it with 7-Zip or any other zip file manager, and you should see all of the .so files there.Shotputter
@SomeCallMeTime : Thanks dude for teaching me how to refer the libs inside an apk. I faced an issue with java.lang.UnsatisfiedLinkError: No implementation found for nativeNewInstance android autonavi map . I am adding two third party jni libraries in my code. and found that one lib supports multiple cpu architecture and one supports only armeabi, so I removed the other architectures from the one that supports multiple cpu and put only the armeabi files in my project and it is working fine nowCopy
B
0

It is completely find to load multiple native libs. Just copy them into /libs/CPU_ARCH/ directory. However all the libs need to be of same architecture. If let say libfoo.so is armeabi but libbar.so is x86 then only one will be copied (as of my trial some time ago).

Then you can load it:

static {
    //the following 3 are identical
    //System.load(context.getApplicationInfo().dataDir + "/lib/libfoo.so");
    //Runtime.getRuntime().load(context.getApplicationInfo().dataDir + "/lib/libfoo.so");
    System.loadLibrary("foo");

    System.loadLibrary("bar");
}

If System.loadLibrary() fail, then you can try load with full path using System.load() or Runtime.getRuntime().load()

Buckden answered 4/10, 2013 at 2:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.