简体   繁体   English

如何在64位Android设备上使用32位本机库

[英]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.

相关问题 在 64 位 android 上使用 32 位 jni 库 - Use 32-bit jni libraries on 64-bit android DS-5版,用于使用Arm 64位和32位本机库开发和调试Android应用 - DS-5 edition to develop and debug Android Apps with Arm 64-bit and 32-bit native libraries 在 64 位版本的 Lubuntu 上安装 Android Studio 无法安装一些 32 位库 - Intstalling Android Studio on 64-bit version of Lubuntu fails installing some 32-bit libraries Android 设备供应商在 64 位 SOC 上刷入 32 位内核? - Android device vendor flashing 32-bit kernels on 64-bit SOCs? Android JNI:与64位设备具有32位兼容性吗? - Android JNI: 32-bit compatability with 64-bit devices? 将 32 位 android 应用程序转换为 64 位应用程序 - Converting 32-bit android Applications to 64-bit Applications 如何确定apk是32位还是64位 - How to find if apk is 32-bit or 64-bit 如何在我的应用程序中包含 64 位和 32 位本机代码 - How to Include 64-bit and 32-bit native code in my app 为什么Android NDK对于32位和64位ABI使用不同的GCC版本? - Why does the Android NDK use different GCC versions for 32-bit and 64-bit ABIs? 如何在Android棒棒糖中以编程方式知道应用程序的进程是32位还是64位? - How to know a process of an app is 32-bit or 64-bit programmatically in Android lollipop?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM