假设我们在下面有一个 jni 文件夹结构。
armeabi
a.so
b.so
armeabi-v7a
a.so
在基于ARMv7的设备上,我想加载b.so,但是“armeabi-v7a”文件夹下没有b.so,所以系统会报找不到库错误还是使用b.so在“armeabi”文件夹下?
更进一步,系统在armeabi
,armeabi-v7a
,arm64-v8a
,中以什么顺序查找so文件>x86
,x86_64
?例如,在基于x86_64的设备上,系统首先在文件夹x86_64
中寻找so文件,如果没有找到,系统会继续在x86
中寻找文件,arm64-v8a
,armeabi-v7a
,armeabi
按顺序?
最佳答案
你见过吗:http://developer.android.com/ndk/guides/abis.html#am
我相信它可以回答您的问题:
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().
页面的下方是这个特殊的部分:
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.
因此,如果您使用的是 armeabi-v7a 架构,则必须复制 lib/armeabi/libb.so
文件并使用 dlopen(),因为 PackageManager 什么都不知道需要在您的应用中加载但确实在 lib/armeabi-v7a
目录中找到的内容。
关于android - Android系统从armeabi,armeabi-v7a,arm64-v8a加载原生库(so文件)有什么规律?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35860727/