Google Play Console rejects the APK you upload to a testing track because of its version code
Upload new APK to Alpha - failedShort 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.
Fix it fast
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 versionCode2Match what you see, then jump to its fix
- 1
The printed versionCode matches a release you already uploaded, or is lower than itThe versionCode was used by an earlier uploadFix - 2
You changed the number, rebuilt, and the code printed from the APK is still the old oneThe value you edited is overridden somewhere elseFix - 3
The 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
The 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
- 1
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/null2Fix
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 versionCodeConfirmed by developer.android.com
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/null2Fix
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 versionCodeConfirmed by developer.android.com
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/null2Fix
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; doneConfirmed by developer.android.com
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:bundleRelease3Verify
The .aab file exists, and it uploads with the version code you set.
find . -name '*.aab' -not -path './.git/*'Confirmed by developer.android.com
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 fixMobile apps
Google Play rejects the upload because the bundle is signed with the wrong key
Your Android App Bundle is signed with the wrong key. Ensure that your app bundle is signed with the correct signing key and try again.
With Play App Signing, Play Console expects every upload to be signed with your upload key, not the key Google uses to sign installs.
3 causes, each with a fixMobile apps
Android install fails because the version on the device is newer
Failure [INSTALL_FAILED_VERSION_DOWNGRADE]
Android blocks an install whose versionCode is lower than the app already on the device.
3 causes, each with a fixMobile apps
adb cannot start because something already holds its port
adb start-server failed
The adb server must bind local TCP port 5037, and every adb client talks to it there.
2 causes, each with a fixMobile apps
The phone shows as unauthorized and Android Studio will not run the app
adb devices lists the phone but Android Studio cannot deploy to it
An unauthorized phone means it has not trusted this computer's RSA key.
3 causes, each with a fixMobile 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