Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Flutter and app store releases

Google Play Console rejects the APK you upload to a testing track because of its version code

ErrorUpload new APK to Alpha - failed

Short answer

Google Play will not take an APK whose versionCode you already used for an earlier version. Read the code inside the file you are uploading, then raise versionCode in the module's Gradle file and rebuild. Also check that a flavor or build type does not override it, that split APKs have different codes, and that a new app goes up as a bundle.

  • Applies to Android Gradle Plugin 8, Android Studio, Google Play Console
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Print the version code that is inside the exact APK you are about to upload. If it equals a code you uploaded before, that is the problem, whatever the Gradle file says.

    aapt2 dump badging app/build/outputs/apk/release/app-release.apk | grep versionCode
  2. 2Match what you see, then jump to its fix

    1. 1The printed versionCode matches a release you already uploaded, or is lower than itThe versionCode was used by an earlier uploadFix
    2. 2You changed the number, rebuilt, and the code printed from the APK is still the old oneThe value you edited is overridden somewhere elseFix
    3. 3The build makes one APK per ABI, and the upload of the second or third one is refusedSeveral APKs of one release share the same codeFix
    4. 4The app is new in Play Console and the file you build for upload ends in .apk, not .aabA new app is uploaded as an APK instead of an app bundleFix

What does the error look like?

  • Upload new APK to Alpha - failed

Cause 1 of 4

The versionCode was used by an earlier upload

1Check

Android's documentation says you cannot upload an APK to the Play Store with a versionCode you have already used for a previous version, and that each new release must use a greater value. The value is a positive integer, and Google Play allows 2100000000 at most.

grep -n -E 'versionCode|versionName' app/build.gradle app/build.gradle.kts 2>/dev/null

2Fix

Raise versionCode in the defaultConfig block by at least one, then rebuild and upload the new file.

android {
    defaultConfig {
        versionCode = 8     // was 7
        versionName = "1.4"
    }
}

3Verify

Rebuild and read the code from the new APK.

./gradlew assembleRelease
aapt2 dump badging app/build/outputs/apk/release/app-release.apk | grep versionCode

Confirmed by developer.android.com

Did this fix it?

Cause 2 of 4

The value you edited is overridden somewhere else

1Check

Version values in the Gradle build file override the ones in the manifest, and a product flavor or build type can override the defaultConfig value again. So a number edited in AndroidManifest.xml, or in defaultConfig while a flavor sets its own, never reaches the APK.

grep -n -E 'versionCode' app/build.gradle app/build.gradle.kts app/src/main/AndroidManifest.xml 2>/dev/null

2Fix

Keep the version settings in one place, the Gradle file, and remove versionCode and versionName from the manifest element. If a flavor needs its own value, change it there.

android {
    defaultConfig {
        versionCode = 8
    }
    productFlavors {
        create("full") {
            // no versionCode here: it uses the default
        }
    }
}

3Verify

The APK now reports the new code.

./gradlew assembleRelease
aapt2 dump badging app/build/outputs/apk/release/app-release.apk | grep versionCode

Confirmed by developer.android.com

Did this fix it?

Cause 3 of 4

Several APKs of one release share the same code

1Check

By default Gradle gives every split APK the same version information, and the Play Store does not allow several APKs of one app with identical version information. Each APK needs its own versionCode before you upload.

ls app/build/outputs/apk/release/
grep -n -E 'splits|abi' app/build.gradle app/build.gradle.kts 2>/dev/null

2Fix

Give each ABI its own code, with a mapping in the build file as Android's APK-splits guide shows, or switch to one app bundle.

// top of app/build.gradle.kts
import com.android.build.api.variant.FilterConfiguration.FilterType.*

val abiCodes = mapOf("armeabi-v7a" to 1, "x86" to 2, "x86_64" to 3)

androidComponents {
    onVariants { variant ->
        variant.outputs.forEach { output ->
            val name = output.filters.find { it.filterType == ABI }?.identifier
            val baseAbiCode = abiCodes[name]
            if (baseAbiCode != null) {
                output.versionCode.set(baseAbiCode * 1000 + (output.versionCode.get() ?: 0))
            }
        }
    }
}

3Verify

Each APK now reports a different code.

./gradlew assembleRelease
for f in app/build/outputs/apk/release/*.apk; do aapt2 dump badging "$f" | grep versionCode; done

Confirmed by developer.android.com

Did this fix it?

Cause 4 of 4

A new app is uploaded as an APK instead of an app bundle

1Check

Android's documentation states that since August 2021, all new apps must be published as App Bundles, and that Play generates and serves the optimized APKs from the bundle. A bundle is not installed on a device directly.

find . -name '*.aab' -not -path './.git/*'

2Fix

Build the bundle of the release variant with the module's bundle task. The release build type must have its signing configuration, so the bundle is signed for upload.

./gradlew :app:bundleRelease

3Verify

The .aab file exists, and it uploads with the version code you set.

find . -name '*.aab' -not -path './.git/*'

Confirmed by developer.android.com

Did this fix it?

How do I stop it coming back?

  • Increase versionCode in the same commit that creates the release, and let CI fail when the code did not change.
  • Generate the code from a build counter, with room to spare, so that no two uploads ever share one.
  • Define versionCode and versionName only in Gradle, never also in the manifest.
  • Read the code from the final file with aapt2 dump badging before you upload.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Mobile apps

Google Play says your upload was signed in debug mode

You uploaded an APK that was signed in debug mode. You need to sign your APK in release mode.

Google Play does not accept anything signed with the debug certificate that Android tools create for development.

3 causes, each with a fix

Mobile apps

Android Studio cannot pair the phone over Wi-Fi

The Pair devices over Wi-Fi dialog lists no device

Wireless pairing needs the phone on Android 11 or higher and on the same Wi-Fi network as the computer, with current Platform-Tools.

4 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.