60

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

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)

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

4

2 回答 2

146

当您在Android上安装APK时,系统会lib在APK文件夹内查找原生库目录(armeabi、armeabi-v7a、arm64-v8a、x86、x86_64、mips64、mips),顺序由Build.SUPPORTED_ABIS.

如果您的应用碰巧有一个arm64-v8a缺少库的目录,则不会从另一个目录安装缺少的库,也不会混合这些库。这意味着您必须为每个架构提供全套库。

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

android {
    ....
    defaultConfig {
        ....
        ndk {
            abiFilters "armeabi", "armeabi-v7a", "x86", "mips"
        }
    }
}
于 2015-06-12T09:34:15.417 回答
7

上面的答案将有助于生成只有 32 位而不是 64 位的构建。如果您使用 [ abiFilters "armeabi", "armeabi-v7a", "x86", "mips" ]。生成签名的 apk 意味着,这不适用于 64 位。当我们上传到 Google Play 商店时会报错。它不是 64 位版本。

于 2019-09-17T07:05:03.120 回答