Android App Bundle(仅限) - 无法加载原生库

标签 android gradle native

几个月前,我在 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/

相关文章:

java - 使用 Gradle 运行单元测试时,最大堆大小在哪里设置?

ios - 错误 : ld: warning: ignoring file libfile01. a,文件是为存档而构建的,该存档不是正在链接的架构 (armv7) : libfile01. a

compiler-construction - 使编译后的二进制文件以 native 速度完美运行,而无需从另一个系统上的源代码重新编译?

android - Android Studio Gradle错误

单击按钮时 Android ViewModel LiveData 更新 View

android - 在 ARM 模拟器上编译以在 Android 手机上使用

android - 错误 :exception during working with external system

gradle - 更新 build.gradle 时 IntelliJ 模块设置发生变化

java - 我可以在 Android 应用程序中使用 Google map 以外的 map 服务器吗?

java - 我在哪里可以找到有关 AWT 如何与 native 操作系统交互的详细信息?