几个月前,我在 Google Play 生产中切换到 Android App Bundle (ABB) 并发布了几个更新 - 一切都很好。上周我进行了 Android Studio 更新并注意到只有 ABB 构建无法在运行时加载我的 native 库之一。但是 APK 构建(发布)和调试构建可以很好地加载 native 库。
我被迫部署一个 APK 来替换生产中损坏的 ABB 版本。
我发现 ABB 包包含所有四个(arm64-v8a、armeabi-v7a、x86、x86_64)目录,并且我所有的 .SO 文件都在其中(与 APK 包中的相同)。
为了进一步调查,我编辑了 Android Studio 运行配置以部署“应用程序包中的 APK”,并验证 native 库无法加载仅用于 ABB 构建(其他构建模式很好)。
我的环境 :Android Studio 4.0(目前最新),
'io.fabric.tools:gradle:1.28.0'(ABB 一直工作到 1.26.1),
compileSdkVersion 28,
buildToolsVersion '28.0.3'
回滚最新更新没有简单的方法。请让我知道如何解决此构建问题。感谢你的帮助。
最佳答案
终于找到了解决这个问题的方法。我使用的第三方库不符合最近的 Gradle 更改。当在设备上从 ABB 构建 APK 时,库的 Java 代码不知道其 SO 文件的正确路径。 gradle.properties 文件中的设置效果很好。
根据Gradle release note
When building an Android App Bundle, APKs generated from that app bundle that target Android 6.0 (API level 23) or higher now include uncompressed versions of your native libraries by default. This optimization avoids the need for the device to make a copy of the library and thus reduces the on-disk size of your app. If you'd rather disable this optimization, add the following to your gradle.properties file:
android.bundle.enableUncompressedNativeLibs = false
关于Android App Bundle(仅限) - 无法加载原生库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62807988/