如何使用32位本机libaries在64位的Andr​​oid设备 [英] How to use 32-bit native libaries on 64-bit Android device

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

问题描述

我用我的应用程序本机库,这只是编译armeabi,armeabi-V7A和x86。

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

在该库是像三星S6,用的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,86,x86_64的,MIPS64, MIPS)的 LIB 文件夹中的APK的,由 Build.SUPPORTED_ABIS 确定的次序进去。

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 目录中缺少的库中,缺少的库,将无法从另一个目录中安装时,库不混合。这意味着你必须提供全套的库的每个架构。

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"
        }
    }
}

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

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