如何在64位Android设备上使用32位本机库 [英] How to use 32-bit native libraries on 64-bit Android device

查看:464
本文介绍了如何在64位Android设备上使用32位本机库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在应用程序中使用一个本机库,该库仅针对armeabi,armeabi-v7a和x86进行编译.

I use a native library in my application that is only compiled for armeabi, armeabi-v7a and x86.

当该库加载到三星S6之类的64位设备上时,应用程序崩溃,并显示UnsatisfiedLinkError

When this library is loaded on a 64-bit device like the Samsung S6, the application crashes with an 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)

不幸的是,该库是封闭源.有什么方法可以解决此问题,而无需使用64位目标重新编译该库?

The library is closed source unfortunately. Is there any way to fix this without recompiling the library with 64-bit targets?

推荐答案

在Android上安装APK时,系统会查找本机库目录(armeabi,armeabi-v7a,arm64-v8a,x86,x86_64,mips64,按Build.SUPPORTED_ABIS确定的顺序在APK的lib文件夹中).

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.

如果您的应用程序恰好有一个arm64-v8a目录,其中包含缺少的lib,则不会从其他目录中安装缺少的lib,因此不会混用这些lib.这意味着您必须为每种架构提供完整的库集.

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. That means you have to provide the full set of your libraries for each architecture.

因此,要解决您的问题,可以从构建中删除64位库,或将abiFilters设置为仅打包32位体系结构:

So, to solve your issue, you can remove your 64-bit libs from your build, or set abiFilters to package only 32-bit architectures:

android {
    ....
    defaultConfig {
        ....
        ndk {
            abiFilters "armeabi", "armeabi-v7a", "x86", "mips"
        }
    }
}

这篇关于如何在64位Android设备上使用32位本机库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆