Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's rule does Android system load native library(so file) from armeabi,armeabi-v7a,arm64-v8a?

Assume we have a jni folder structure below.

armeabi
    a.so
    b.so
armeabi-v7a
    a.so

On a ARMv7-based device, I want to load b.so, but the there is no b.so under folder "armeabi-v7a", so will the system report a not found library error or use the b.so under folder "armeabi"?

And even more, what order does system look for a so file among armeabi,armeabi-v7a,arm64-v8a,x86,x86_64? For example, on a x86_64-based device, system look for the so file in folder x86_64 first, but if not found, will system continue to look for the file in x86,arm64-v8a,armeabi-v7a,armeabi in sequence?

like image 335
Riki Avatar asked Feb 08 '23 13:02

Riki


1 Answers

Have you seen: http://developer.android.com/ndk/guides/abis.html#am

I believe it answers your questions:

Both the Play Store and Package Manager expect to find NDK-generated libraries on filepaths inside the APK matching the following pattern:

/lib/<abi>/lib<name>.so

If the system does not find the native shared libraries where it expects them, it cannot use them. In such a case, the app itself has to copy the libraries over, and then perform dlopen().

Further down the page is this particular bit:

Automatic extraction of native code at install time

When installing an application, the package manager service scans the APK, and looks for any shared libraries of the form:

lib/<primary-abi>/lib<name>.so

If none is found, and you have defined a secondary ABI, the service scans for shared libraries of the form:

lib/<secondary-abi>/lib<name>.so

When it finds the libraries that it's looking for, the package manager copies them to /lib/lib.so, under the application's data directory (data/data//lib/). If there is no shared-object file at all, the application builds and installs, but crashes at runtime.

So in your case if you are on a armeabi-v7a architecture, you'll have to copy the lib/armeabi/libb.so file over and use dlopen() as the PackageManager knows nothing of what needs to be loaded in your app but did find something in the lib/armeabi-v7a directory.

like image 152
Morrison Chang Avatar answered Feb 15 '23 11:02

Morrison Chang