busylee
busylee

Reputation: 2560

Android NDK, could not find dependent library

I tried to implement NDK shared library needed other external native library compiled in Linux as .so file.

I have the following relationship: libl1 depends on libl2.

I tried prebuilt libl2.so as shared and added it into libl1 module. Everything compiled fine and on my LG Nexus 4 works fine when I load libl1 like this:

static {
  System.loadLibrary('l1');
}

But it doesn't work on Samsung 4.03 Android version. In this device it works with this code:

static {
  System.loadLibrary('l2');
  System.loadLibrary('l1');
}

I found that Android ClassLoader can not load dependency. But why does it work fine on Nexus 4? But not the Samsung device?

Upvotes: 1

Views: 372

Answers (1)

Alex Cohn
Alex Cohn

Reputation: 57173

The behavior you see on Nexus4 is not expected, and I tested again that there is no special treatment, at least on v. 4.2.2 (build JDQ39). Maybe you have some other Android installed on your Nexus? Maybe your device happens to have file /system/lib/libl2.so for any reason?

The behavior of your Samsung device is expected, and it is what Android team thinks is correct. All shared libraries must be loaded in the order of their dependency from Java, or you can always call dlopen() explicitly if you wish, but loose all the simplicity of using the linker to resolve function references across these shared libraries for you.

Upvotes: 2

Related Questions