如何在Gradle 3+上拆分ABI以更改版本代码?

时间:2018-06-22 18:22:40

标签: android gradle google-play abi

根据https://issuetracker.google.com/issues/64747519和Google文档https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration#variant_api提出的问题,变体API不再可用于更改或更改版本代码的运行时间。

那么我们如何创建多个APK并将其上传到Google Play商店?

这是我的代码段

splits {
    abi {
        // Enables building multiple APKs per ABI.
        enable true

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

        // Specifies a list of ABIs that Gradle should create APKs for.
        include "x86", "x86_64", "armeabi-v7a", "arm64-v8a"

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

// Map for the version code that gives each ABI a value.
def abiCodes = ['x86': 1, 'x86_64': 2, 'armeabi-v7a': 3, 'arm64-v8a': 4]

// APKs for the same app that all have the same version information.
android.applicationVariants.all { variant ->
    // Assigns a different version code for each output APK.
    variant.outputs.each {
        output ->
            def abiName = output.outputFile
            output.versionCodeOverride = abiCodes.get(abiName, 0) * 100000 + variant.versionCode
    }
}

0 个答案:

没有答案