Signing, bundles and Play release tracks

Learn Android app signing for Google Play: Play App Signing with an upload key, App Bundles, versionCode rules, and internal to production release tracks. About 25 minutes.

Why it matters

  • Play App Signing and Android App Bundles are required for new apps on Google Play. Interviewers ask you to explain the upload key versus app signing key split and why an APK upload is refused.
  • A reused versionCode or an APK instead of an .aab stops a release at upload time. Knowing the exact rules saves hours in CI.
  • Release tracks (internal, closed, open, production) and staged rollouts are how you ship safely; jumping straight to 100% of production turns one bug into an incident for every user.
  • Losing the upload key is recoverable with Play App Signing; losing an app signing key you managed yourself is not. Knowing the difference is a senior-level answer.

The simple explanation

  • You post a parcel (your .aab) to a sorting office (Google Play).
  • You seal it with your own stamp (the upload key) so the office knows it came from you.
  • The office repacks it for each address and seals it with the official seal (the app signing key) that every recipient recognises.
  • If you lose your stamp, the office can register a new one for you; the official seal never changes.
  • The office has lanes: internal, closed, open and production, and it can deliver to a share of the city first.

How does Android app signing work on Google Play? With Play App Signing, Google stores your app's app signing key and uses it to sign the APKs it delivers to devices. You sign each upload with a separate upload key that only proves to Play the upload came from you. If the upload key is lost or leaked, the account owner requests an upload key reset in Play Console; the app signing key, which installed apps trust, stays the same.

An Android App Bundle (.aab) is the publishing format required for new apps on Google Play. It contains all code and resources; Play uses it to generate optimised APKs for each device configuration (screen density, CPU architecture, language). You build it with ./gradlew bundleRelease.

versionCode is a positive integer that must be higher for each new release; Android refuses to install a lower versionCode over a higher one, and Play will not accept an upload whose versionCode was already used for the app. versionName is a free-text string for users (e.g. 2.4.1) that the system never compares.

TrackAudienceNotes
Internal testinga small list of testers you add by emailquick to reach testers; may skip the standard review
Closed testingtesters by email list or Google Groupreviewed by Google
Open testinganyone who joins from Google Play or a linkreviewed by Google
Productionall users in the chosen countriesreviewed; supports staged rollouts

You can promote the same release from one track to another, so the exact build testers used reaches users. A production release can be a staged rollout to a percentage of users that you increase, halt or resume from Play Console or the Play Developer API.

In practice teams automate uploads with Gradle Play Publisher or fastlane supply from a CI pipeline that also runs lint and unit tests (see the CI/CD pipelines lesson).

Notes

  • Play App Signing: Google holds the app signing key; you hold the upload key. Keep the upload keystore and its passwords in a secrets manager or CI secrets, never in source control.
  • Lost or leaked upload key: create a new one, export its certificate (keytool -export -rfc ...) and the account owner requests an upload key reset in Play Console (the App integrity page). The app signing key does not change.
  • The upload key must be an RSA key of at least 2048 bits. Generate it with keytool -genkeypair.
  • New apps must be published as an Android App Bundle (.aab). Play generates per-device APKs from it. To test a bundle locally, use bundletool to build APKs from it.
  • versionCode: each upload needs a value never used before for the app, and users only get an update when it is higher than what they have installed. The highest value Google Play allows is 2100000000.
  • versionName is shown to users and never compared by the system.
  • Internal testing releases may not go through the standard review, which makes that track the fastest way to get a build to testers. Closed, open and production releases are reviewed.
  • New personal developer accounts must run a closed test with a minimum number of testers before they can publish to production; check the current requirement in Play Console Help.
  • A staged rollout sends a release to a percentage of users. Halting it stops new installs; users who already updated keep the new version.
  • In-app updates use AppUpdateManager (AppUpdateManagerFactory.create(context)); in-app reviews use ReviewManager (ReviewManagerFactory.create(context)). Play applies a quota to review prompts, so the dialog may not appear every time you ask.

Code example

Create the upload key once, then let Gradle read it from environment variables so the keystore never enters the repository.

# Run once on a trusted machine. Store the file and passwords in your secrets manager.
keytool -genkeypair -v -keystore upload-keystore.jks \
  -keyalg RSA -keysize 2048 -validity 10000 -alias upload
// app/build.gradle.kts
plugins {
    id("com.android.application")
    id("com.github.triplet.play") // Gradle Play Publisher
}
 
android {
    signingConfigs {
        create("upload") {
            val path = System.getenv("UPLOAD_KEYSTORE_PATH")
            if (path != null) {
                storeFile = file(path)
                storePassword = System.getenv("UPLOAD_KEYSTORE_PASSWORD")
                keyAlias = System.getenv("UPLOAD_KEY_ALIAS")
                keyPassword = System.getenv("UPLOAD_KEY_PASSWORD")
            }
        }
    }
    buildTypes {
        release {
            if (System.getenv("UPLOAD_KEYSTORE_PATH") != null) {
                signingConfig = signingConfigs.getByName("upload")
            }
        }
    }
}
 
play {
    // Service-account JSON is read from the ANDROID_PUBLISHER_CREDENTIALS env var.
    track.set("internal")
    defaultToAppBundles.set(true)
}
# Build the signed .aab and upload it to the internal track
./gradlew publishReleaseBundle
 
# Promote the same release to production as a 10% staged rollout
./gradlew promoteArtifact --from-track internal --promote-track production \
  --release-status inProgress --user-fraction .1
 
# Later: raise the rollout, then finish it
./gradlew promoteArtifact --update production --user-fraction .5
./gradlew promoteArtifact --update production --release-status completed
  • bundleRelease (run by publishReleaseBundle) produces an .aab signed with the upload key; Play signs the delivered APKs with the app signing key.
  • The keystore path and passwords come from environment variables set by CI, never from a committed file.
  • Promoting reuses the release already on the internal track, so production gets the exact build testers used, with the same versionCode.
  • Gradle Play Publisher rejects a user fraction of 1.0; you finish a rollout by setting the status to completed.

Run the idea in plain Kotlin

data class Release(val versionCode: Int, val versionName: String, val track: String)

val tracks = listOf("internal", "closed", "open", "production")

fun canUpload(usedCodes: Set<Int>, newCode: Int): String = when {
  newCode <= 0 -> "rejected: versionCode must be positive"
  newCode > 2_100_000_000 -> "rejected: above Play's maximum"
  newCode in usedCodes -> "rejected: versionCode " + newCode + " already used"
  newCode < (usedCodes.maxOrNull() ?: 0) -> "accepted, but installed users on a higher code will not get it"
  else -> "accepted"
}

fun nextTrack(current: String): String? {
  val idx = tracks.indexOf(current)
  return if (idx < 0 || idx == tracks.lastIndex) null else tracks[idx + 1]
}

fun main() {
  val used = setOf(100, 101, 102)
  for (code in listOf(103, 101, 99)) {
      println("Upload versionCode " + code + ": " + canUpload(used, code))
  }

  println("Promotion path:")
  var current: String? = "internal"
  while (current != null) {
      println("  -> " + current)
      current = nextTrack(current)
  }

  val release = Release(103, "2.1.0", "production")
  println("Release " + release.versionName + " (code " + release.versionCode + ") on " + release.track)
}

Expected output:

Upload versionCode 103: accepted
Upload versionCode 101: rejected: versionCode 101 already used
Upload versionCode 99: accepted, but installed users on a higher code will not get it
Promotion path:
  -> internal
  -> closed
  -> open
  -> production
Release 2.1.0 (code 103) on production

In production

Lost upload key during an urgent fix
  • The only copy of the upload keystore was on a developer laptop that was lost, with no backup.
  • A crash fix was ready, but every upload was rejected because the bundle was signed with a different key.
  • The team assumed the app was lost and considered publishing a new listing.
The fix
  • Because the app used Play App Signing, the account owner generated a new upload key, exported its certificate and requested an upload key reset in Play Console.
  • Once Google registered the new upload key, uploads worked again. Installed apps updated normally because the app signing key never changed.
  • The new keystore is stored in a secrets manager and CI secrets, with a written recovery runbook.
versionCode collision on parallel branches
  • Two branches both set versionCode = 200 in build.gradle.kts.
  • The first one uploaded. The second upload was rejected because version code 200 had already been used.
  • The release waited while someone picked a new number and rebuilt.
The fix
  • versionCode is now stamped by CI from one increasing counter and is no longer edited by hand.
  • Only main produces release builds, so there is one line of version codes.
  • The upload step uses Gradle Play Publisher; its ResolutionStrategy.AUTO option is an extra guard that picks a code above the latest one on Play.

Common mistakes

  • Uploading an APK for a new app. New apps must use an Android App Bundle. Run ./gradlew bundleRelease and upload the .aab from app/build/outputs/bundle/release/.
  • Reusing a versionCode. Play refuses any upload whose versionCode was already used for the app. Generate it in CI instead of hardcoding it on several branches.
  • Storing the upload keystore in source control. Anyone with repo access can sign uploads. Keep it in a secrets manager and pass it to CI as a secret.
  • Having a single copy of the upload key. It is recoverable with a reset, but that takes time during an incident. Back up the keystore and passwords in a secrets manager.
  • Going to 100% of production immediately. A bad release reaches every user. Start a staged rollout, watch crash and ANR rates in Android vitals, then increase.
  • Asking for a review on every app open. Play limits how often the review dialog is shown, so most requests show nothing. Ask after a meaningful moment, and never from a button that promises a review dialog.

Interview questions

Answer out loud first. Then reveal the answer and compare it at each depth.

“Explain Play App Signing and why it matters.”

“What is an Android App Bundle and when is it required?”

“Walk through a release from internal testing to production.”

“How do flexible and immediate in-app updates differ?”

Quiz

What does Play App Signing do?

Which versionCode can you upload to Play?

Which track is the quickest way to get a build to a small group of trusted testers, even before the app is fully set up?

Your upload key is lost but the app uses Play App Signing. What do you do?

0 of 4 answered

Mini task

Sign a bundle with an upload key and ship it to internal testing (15 min)

  1. Generate an upload key with keytool -genkeypair -v -keystore upload-keystore.jks -keyalg RSA -keysize 2048 -validity 10000 -alias upload. Keep the file outside the repo and add *.jks to .gitignore.

  2. Add a signingConfigs block in app/build.gradle.kts that reads the keystore path and passwords from environment variables, as in the example, and use it for the release build type.

  3. Export the variables in your shell and run ./gradlew bundleRelease. Confirm app/build/outputs/bundle/release/app-release.aab exists.

  4. In Play Console, open Test and release > Testing > Internal testing, create a release and upload the .aab (or use Gradle Play Publisher's publishReleaseBundle). Add yourself as a tester.

  5. Open the Play App Signing page under App integrity and note the two certificates: app signing key and upload key.

  6. Try uploading the same .aab again. Read the rejection about the version code, then bump versionCode, rebuild and upload again.

Done when: a signed .aab is on the internal testing track, you have seen the reused version code rejection, and you can point to both certificates on the Play App Signing page.

Next: Staged rollouts and in-app updates