减少APK大小-仅针对特定平台构建文件

时间:2019-04-22 18:08:16

标签: android gradle apk

我正在尝试减少我的Android应用。它有一个不同的程序包,一个客户端程序包,它依赖于其他程序包。我正在分析APK,看到有这样的文件适用于x86和armeabi-v7a等不同的格式。我现在不想要x86。我正在使用split来限制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文件。有人可以帮我解决我做错的事情吗?

1 个答案:

答案 0 :(得分:0)

使用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'
        }
    }
}