Delivery cheat sheet
Key ideas
- New apps must upload an Android App Bundle (
.aab); run./gradlew bundleRelease, notassembleRelease. - Play App Signing splits keys: you hold the upload key, Google holds the app signing key; a lost upload key is reset in Play Console.
versionCodemust be a unique, increasing integer (max 2100000000); stamp it in CI from one counter, never hand-edit on branches.- Staged rollouts start at a small percentage; halting stops new installs but does not roll back—ship a fix with a higher
versionCode. AppUpdateManagerwithstartUpdateFlowForResultdrives in-app updates; flexible updates inInstallStatus.DOWNLOADEDneedcompleteUpdate().- CI runs
lintDebugandtestDebugUnitTeston every PR; build and publish the signed.aabonly frommainor a release tag. - Keep the upload keystore and service-account JSON in CI secrets, never in source control; never
echoa decoded secret. - Trunk-based development: small merges to
main, releases tagged frommain, one version counter, no long-lived release branches. - Gradle Play Publisher (
com.github.triplet.play) reads credentials fromANDROID_PUBLISHER_CREDENTIALS;publishReleaseBundleuploads to a track. versionNameis display-only free text; Android and Play never compare it—useversionCodefor any version logic.
APIs at a glance
| API or term | Use it for |
|---|---|
actions/checkout, actions/setup-java, gradle/actions/setup-gradle | Standard GitHub Actions steps; the Gradle action handles build caching automatically. |
./gradlew bundleRelease | Produce the .aab that new apps must upload to Play; replaces assembleRelease. |
com.github.triplet.play | Gradle Play Publisher plugin; reads ANDROID_PUBLISHER_CREDENTIALS and runs publishReleaseBundle. |
AppUpdateManagerFactory.create(context) | Obtain the AppUpdateManager for in-app updates; pair with app-update-ktx. |
startUpdateFlowForResult(info, launcher, options) | Launch an immediate or flexible update; each AppUpdateInfo can start a flow only once. |
InstallStatus.DOWNLOADED | Flexible-update state where Play has downloaded but not installed; call completeUpdate() after a restart prompt. |
UpdateAvailability.DEVELOPER_TRIGGERED_UPDATE_IN_PROGRESS | Resume an immediate update the app started in a previous session, checked in onResume. |
versionCode | Unique positive integer per upload; users update only when the new value is higher; max 2100000000. |
keytool -genkeypair -keyalg RSA -keysize 2048 | Generate the upload keystore; store it and its passwords in a secrets manager. |
ANDROID_PUBLISHER_CREDENTIALS | Environment variable holding the Play service-account JSON; keeps the key file out of the repo. |
FakeAppUpdateManager | Simulate the in-app update flow in unit tests without a real Play connection. |
gradle/libs.versions.toml | Single version catalog so modules do not drift on dependency versions. |
Snippets
CI workflow: lint, test, then release from main
name: Android CI
on:
pull_request:
push:
branches: [main]
jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-java@v5
with: {distribution: temurin, java-version: 17}
- uses: gradle/actions/setup-gradle@v6
- run: ./gradlew lintDebug testDebugUnitTest
release:
needs: check
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-java@v5
with: {distribution: temurin, java-version: 17}
- uses: gradle/actions/setup-gradle@v6
- name: Decode upload keystore
env:
UPLOAD_KEYSTORE_BASE64: ${{ secrets.UPLOAD_KEYSTORE_BASE64 }}
run: printf '%s' "$UPLOAD_KEYSTORE_BASE64" | base64 --decode > "$RUNNER_TEMP/upload.jks"
- name: Build and upload to the internal track
env:
ANDROID_PUBLISHER_CREDENTIALS: ${{ secrets.PLAY_SERVICE_ACCOUNT_JSON }}
VERSION_CODE: ${{ github.run_number }}
run: ./gradlew publishReleaseBundle --track internalChoose immediate vs flexible in-app update
class MainActivity : ComponentActivity() {
private val appUpdateManager by lazy { AppUpdateManagerFactory.create(this) }
private val updateLauncher =
registerForActivityResult(ActivityResultContracts.StartIntentSenderForResult()) { }
private fun checkForUpdate() {
appUpdateManager.appUpdateInfo.addOnSuccessListener { info ->
if (info.updateAvailability() != UpdateAvailability.UPDATE_AVAILABLE) return@addOnSuccessListener
val type = when {
info.updatePriority() >= 4 && info.isUpdateTypeAllowed(AppUpdateType.IMMEDIATE) ->
AppUpdateType.IMMEDIATE
info.isUpdateTypeAllowed(AppUpdateType.FLEXIBLE) -> AppUpdateType.FLEXIBLE
else -> return@addOnSuccessListener
}
appUpdateManager.startUpdateFlowForResult(
info, updateLauncher, AppUpdateOptions.newBuilder(type).build()
)
}
}
}Generate the upload keystore once
keytool -genkeypair -v -keystore upload-keystore.jks \
-keyalg RSA -keysize 2048 -validity 10000 -alias uploadBump versionName and tag for CI release
#!/usr/bin/env bash
set -euo pipefail
BUMP="${1:-patch}"
CUR_NAME=$(grep '^versionName=' gradle.properties | cut -d= -f2)
IFS='.' read -r MAJ MIN PAT <<< "$CUR_NAME"
case "$BUMP" in
major) MAJ=$((MAJ+1)); MIN=0; PAT=0 ;;
minor) MIN=$((MIN+1)); PAT=0 ;;
patch) PAT=$((PAT+1)) ;;
esac
NEW="${MAJ}.${MIN}.${PAT}"
sed -i.bak "s/^versionName=.*/versionName=${NEW}/" gradle.properties && rm gradle.properties.bak
git commit -am "Release ${NEW}"
git tag "v${NEW}"Rules of thumb
- Prefer
bundleReleaseoverassembleRelease; new Play apps must receive an.aab, not an APK. - Never commit the upload keystore, service-account JSON, or any decoded secret to source control.
- Never
echoa base64-decoded secret or runset -xaround a command that uses one; log masking is bypassed. - Prefer a single CI-stamped
versionCodecounter (e.g.github.run_number+ offset) over hand-editing on branches. - Never release to 100 % of production at once; start a staged rollout and watch Android vitals before increasing.
- Prefer trunk-based development: merge small changes to
main, tag releases frommain, keep one version counter.
Gotchas
- Building APKs with assembleRelease for a new app. Play rejects the upload because new apps must use an Android App Bundle. Run
./gradlew bundleReleaseand upload the.aabfromapp/build/outputs/bundle/release/. - Hand-bumping versionCode on several branches. Two branches pick the same number and the second upload is rejected, or a lower number means users never update. Stamp it in CI from one counter.
- Forgetting the InstallStatus.DOWNLOADED state in flexible updates. Play downloads the update but never installs it, so the user stays on the old version. Show a restart prompt and call
appUpdateManager.completeUpdate(). - Assuming halting a staged rollout rolls users back. Halting only stops new installs; users who already updated keep the new build. Ship a fixed release with a higher
versionCode. - Using versionName for version comparison in code. It is free text and string-sorts incorrectly (e.g.
"2.10.0"before"2.9.0"). CompareversionCodeinstead. - Printing a secret with echo or running set -x around a secret-using command. GitHub Actions masks registered secret values, but a transformed (e.g. base64-decoded) value is not masked. Write secrets to files or env vars, never to stdout.
Quick interview answers
What is Play App Signing and who holds each key?
Play App Signing means Google holds the app signing key that signs the APKs users install, while you hold the upload key that signs the .aab in CI. If the upload key is lost or leaked, the account owner requests an upload key reset in Play Console; the app signing key does not change.
How do you implement in-app updates with the current Play API?
Add com.google.android.play:app-update and app-update-ktx, create an AppUpdateManager via AppUpdateManagerFactory.create(context), and call startUpdateFlowForResult with an ActivityResultLauncher. For flexible updates, watch for InstallStatus.DOWNLOADED and call completeUpdate() after showing a restart prompt; in onResume, resume any DEVELOPER_TRIGGERED_UPDATE_IN_PROGRESS.
How should versionCode be managed in a multi-branch CI setup?
Stamp versionCode in CI from a single counter such as github.run_number plus an offset so no two branches pick the same value. Each upload must use a value never used before for that app, and users only update when the new value is higher than what they have installed.
What happens when you halt a staged rollout?
Halting stops new installs of that release, but users who already updated keep the new version. To fix a problem you ship a new release with a higher versionCode; halting does not roll anyone back.
Why use trunk-based development for Android releases?
Trunk-based development keeps small changes merged to main and releases tagged from main, so there is one version counter and no long-lived release branches that can miss hotfixes. It avoids the regression risk of a fix on a release branch that never merges back.
How does Gradle Play Publisher authenticate without a key file in the repo?
The plugin com.github.triplet.play reads the service-account JSON from the ANDROID_PUBLISHER_CREDENTIALS environment variable, so the key file never exists in the repository. You store the JSON as a CI secret and pass it through that variable at build time.