Search code examples
androidsplitapk

differentiate VersionCode for ABI and Density without going over the Google Play limit?


The maximum number allowed on Google Play for versioncode is 2100000000 but my app already has a 8 digit version code (2 = Major, 2 = Minor, 1 = Patch, 3 = commit count). That leaves one digit for abi/density version. How do I differentiate between the two so my APKs dont have the same version?

ext.abiCodes = ['armeabi-v7a':1, 'arm64-v8a':2]

// Map for the version code that gives each density a value.
ext.densityCodes = ['mdpi': 1, 'hdpi': 2, 'xhdpi': 3, 'xxhdpi': 4, 'xxxhdpi': 5]

android.applicationVariants.all { variant ->

    // Assigns a different version code for each output APK.
    variant.outputs.each { output ->

        // Indexes: 0 = density/abi version, 1-2 = Major, 3-4 = Minor, 5 = Patch, 6-8 = commit count.
        int baseVersionCode = 100000000

        // Stores the value of ext.densityCodes that is associated with the density for this variant.
        def baseDensityVersionCode =
                // Determines the density for this variant and returns the mapped value.
                project.ext.densityCodes.get(output.getFilter(OutputFile.DENSITY))

        if (baseDensityVersionCode != null) {
            // Set the APK version
            output.versionCodeOverride =
                    baseDensityVersionCode * baseVersionCode + variant.versionCode
        }

        // Stores the value of ext.abiCodes that is associated with the ABI for this variant.
        def baseAbiVersionCode =
                // Determines the ABI for this variant and returns the mapped value.
                project.ext.abiCodes.get(output.getFilter(OutputFile.ABI))

        if (baseAbiVersionCode != null) {
            // Set the APK version
            output.versionCodeOverride =
                    baseAbiVersionCode * baseVersionCode + variant.versionCode
        }
    }
}```

This gives me the same version code for all density variations of a specific abi.

Solution

  • Have you considered publishing an Android App Bundle? This would take care of it since you'd have a single artifact (with a single versionCode) to upload to the Play Console and Play would take care of generating the APKs for the different ABIs and densities (with the same versionCode).

    If for some reason, you don't want to, given that you have 2 ABIs and 5 densities, that's 10 combinations, so that should be enough to fit in a single digit, e.g. (abiNum - 1) * 5 + densityNum.

    But keep in mind that you're sitting on a ticking time bomb since you are going to burn versionCodes much quicker, and also as soon as you decide to support an additional ABI or screen density, this won't work anymore.