64位Android设备上找不到.so文件

6

使用 Android Studio 和 Gradle 构建,使用 Aviary Android SDK。在所有拥有 32 位架构的设备上运行正常。

同一应用在拥有 64 位架构的设备上出现以下错误 [例如 Sony C4]:

    java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file 
"/data/app/com.myapp/base.apk"],nativeLibraryDirectories=[/data/app/com.myapp/lib/arm64, /vendor/lib64, /system/lib64]]] couldn't find "libaviary_moalite.so"

gradle.build部分

dependencies {
    ...
    compile 'com.android.support:multidex:1.0.0'
    compile 'com.facebook.fresco:fresco:0.8.1+'
    compile 'com.facebook.fresco:imagepipeline-okhttp:0.8.1+'
    compile 'com.android.support:appcompat-v7:22.2.1'
    compile 'com.adobe.creativesdk:image:4.0.0'
}

无法解决的参考资料

使用Android Studio(1.3 RC)找不到ARM64 NDK本地库

如果使用任何已用的解决方案,将会出现相同的错误。

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

出现类似以下的错误:

Error:(16, 0) Error: NDK integration is deprecated in the current plugin.  Consider trying the new experimental plugin.  For details, see http://tools.android.com/tech-docs/new-build-system/gradle-experimental.  Set "android.useDeprecatedNdk=true" in gradle.properties to continue using the current NDK integration.

我不确定我做错了什么还是根本不支持。


您是否拥有自己构建的本地库,或者仅从外部来源导入? - Alex Cohn
从 Adobe CreativeSDK 的外部来源导入。 - Umesh Aawte
2个回答

20

看起来你使用的一些软件包带有64位库,但有些没有。为了保持你的APK只有32位,我会使用

android {
    splits {
        abi {
            enable true
            reset()
            include 'armeabi-v7a'
        }
    }
}

如果相关的话,你也可以使用 include 'armeabi' 进行操作。


1
是的,你说得对,有些包含64位库。我会尝试你的解决方案。 - Umesh Aawte
@Alex Cohn:您能告诉我如何查找我的应用程序中哪些库是64位的,哪些是32位的吗?因为使用上述闭包后,我的问题得到了解决。我只使用了一个库,不知道哪些其他库会引发此错误。 - Madhan
@Madhan:这通常发生在使用预编译库时。你会在文件build/intermediates/exploded-aar/??/jni/arm64-v8a/lib???.so中找到这些文件。另外,你也可能会看到x86_64而不是arm64-v8a。你可以安全地从你的APK中删除这些库文件。 - Alex Cohn

7
我用以下步骤解决了这个问题:
  1. I've moved armeabi and x86 folders from: \src\main\jniLibs to: \libs

    Please make sure to move all the files under those folders as well: *.so files should be located there.

  2. I've added the following to my build.gradle:

    sourceSets.main {
      jniLibs.srcDir 'src/main/libs'
    }
    
  3. Clean + rebuild the project

    *in case you are using multidex, please verify that these lines were added to build.gradle:

    defaultConfig {
      multiDexEnabled true
    }
    
    dexOptions {
      preDexLibraries false
      javaMaxHeapSize "4g"
    }
    
此外,您需要在清单文件中添加以下内容:
<application
    android:name="android.support.multidex.MultiDexApplication">
/application>

希望这有所帮助。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接