[英]How to use 32-bit native libraries on 64-bit Android device
I use a native library in my application that is only compiled for armeabi, armeabi-v7a and x86. 我在应用程序中使用仅针对armeabi,armeabi-v7a和x86编译的本机库。
When this library is loaded on a 64-bit device like the Samsung S6, the application crashes with an UnsatisfiedLinkError 当将此库加载到Samsung S6等64位设备上时,应用程序崩溃,并显示UnsatisfiedLinkError
java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.myapp-2/base.apk"],nativeLibraryDirectories=[/data/app/com.myapp-2/lib/arm64, /vendor/lib64, /system/lib64]]] couldn't find "libfoo.so"
at java.lang.Runtime.loadLibrary(Runtime.java:366)
at java.lang.System.loadLibrary(System.java:989)
The library is closed source unfortunately. 不幸的是,该图书馆是封闭的。 Is there any way to fix this without recompiling the library with 64-bit targets?
有什么方法可以解决此问题,而无需使用64位目标重新编译该库?
When you install an APK on Android, the system will look for native libraries directories (armeabi, armeabi-v7a, arm64-v8a, x86, x86_64, mips64, mips) inside the lib
folder of the APK, in the order determined by Build.SUPPORTED_ABIS
. 在Android上安装APK时,系统会按照
Build.SUPPORTED_ABIS
确定的顺序在APK的lib
文件夹中查找本机库目录(armeabi,armeabi-v7a,arm64-v8a,x86,x86_64,mips64,mips) Build.SUPPORTED_ABIS
。
If your app happen to have an arm64-v8a
directory with missing libs, the missing libs will not be installed from another directory, the libs aren't mixed. 如果您的应用程序碰巧有一个
arm64-v8a
目录,其中包含缺少的lib,则不会从其他目录安装缺少的lib,这些lib不会混合在一起。 That means you have to provide the full set of your libraries for each architecture. 这意味着您必须为每种架构提供完整的库集。
So, to solve your issue, you can remove your 64-bit libs from your build, or set abiFilters to package only 32-bit architectures: 因此,要解决您的问题,可以从构建中删除64位库,或将abiFilters设置为仅打包32位体系结构:
android {
....
defaultConfig {
....
ndk {
abiFilters "armeabi", "armeabi-v7a", "x86", "mips"
}
}
}
The above answer will help to generate a build with 32- bit only not a 64-bit. 上面的答案将有助于生成仅32位而不是64位的构建。 If you are using [ abiFilters "armeabi", "armeabi-v7a", "x86", "mips" ].
如果使用[abiFilters“ armeabi”,“ armeabi-v7a”,“ x86”,“ mips”]。 generate signed apk means, that is not for 64 bit.
生成带符号的apk表示,不是64位。 It will raise an error when we upload into Google Play store.
当我们上传到Google Play商店时,它将引发错误。 It is not an 64 bit build.
它不是64位版本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.