【问题标题】:Reducing the APK size - Building so files for only certain platforms减小 APK 大小 - 仅为特定平台构建 so 文件
【发布时间】:2019-04-22 18:08:15
【问题描述】:

我正在尝试减少我的 Android 应用程序。它有一个不同的包,一个客户端包,它依赖于一堆其他包。我正在分析 APK 并看到有用于不同平台的文件,即 x86 和 armeabi-v7a。我目前不想要 x86。我正在使用拆分来限制 x86 平台的 so 文件,并在我的 build.gradle 文件中使用以下代码。

splits {
        abi {
            enable false

            // By default all ABIs are included, so use reset() and include to specify that we only
            // want APKs for x86 and x86_64.

            // Resets the list of ABIs that Gradle should create APKs for to none.
            reset()

            // Specifies a list of ABIs that Gradle should create APKs for.
            include "armeabi-v7a"

            // Specifies that we do not want to also generate a universal APK that includes all ABIs.
            universalApk false
        }
    }

但我仍然可以看到 x86 文件。有人可以帮我解决我做错的事情吗?

【问题讨论】:

  • 你为什么不使用android app-bundle[developer.android.com/platform/technology/app-bundle]?
  • 用proguard怎么样?
  • 感谢@Ezio 分享您的想法。我正在使用 progurard 来排除一些我没有使用的类。但不确定我是否可以专门重构平台。假设我正在使用一个包。我可以限制这个包不使用 proguard 单独为 x86 平台构建和生成吗?

标签: android gradle apk


【解决方案1】:

使用NdkOptions 中的abiFilters 仅包含某些ABI 的本机库。

例子:

android {
    // Similar to other properties in the defaultConfig block, you can override
    // these properties for each product flavor in your build configuration.
    defaultConfig {
        ndk {
            // Tells Gradle to build outputs for the following ABIs and package
            // them into your APK.
            abiFilters 'armeabi', 'armeabi-v7a', 'arm64-v8a'
        }
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-16
    • 2021-10-25
    相关资源
    最近更新 更多