Android code signing
Every Android app is signed with a key before it reaches Google Play. AppRelease keeps the keystore for you and hands it to the build.
How it works
You upload the keystore once, with its passwords, under a reference name. A workflow lists that name under android_signing. Before the scripts run, the runner writes the keystore to a temporary path and exports four environment variables; your Gradle file reads them. When the build ends, the file is deleted.
Upload key vs app signing key
With Play App Signing (the default for every app created since 2021), Google holds the key that signs what users install, and you sign uploads with a separate upload key. That upload key is what you give AppRelease. If you lose it, Google can reset it; if you lose the app signing key of an app that opted out of Play App Signing, nobody can.
Generating a keystore
keytool -genkey -v -keystore upload.keystore -storetype JKS \
-keyalg RSA -keysize 2048 -validity 10000 -alias uploadKeytool asks for a keystore password, then for a key password, then for your name and organisation. The values do not matter to the stores; the passwords do.
Uploading the keystore
- In the console open Credentials → Add credential → Android keystore.
- Pick the
.keystoreor.jksfile. - Enter the keystore password, the key alias and the key password. AppRelease checks them against the file before saving.
- Choose the application it signs, or leave it shared.
- The reference name is filled in for you, for example
shop_upload_keystore. It is the nameapprelease.yamlwould use; the file's own name is not. - Click Save.
apprelease.yaml yourself. Without the file, the runner signs with the keystore linked to the application, or the shared one.Referencing it in apprelease.yaml
workflows:
android-workflow:
environment:
android_signing:
- upload_keystore| Variable | Value |
|---|---|
AR_KEYSTORE_PATH | Absolute path of the keystore on the runner |
AR_KEYSTORE_PASSWORD | Keystore password |
AR_KEY_ALIAS | Key alias |
AR_KEY_PASSWORD | Key alias password |
Wiring it into Gradle
Flutter's template reads key.properties; keep that for local builds and add the CI branch:
android {
signingConfigs {
create("release") {
if (System.getenv("CI") != null) {
storeFile = file(System.getenv("AR_KEYSTORE_PATH"))
storePassword = System.getenv("AR_KEYSTORE_PASSWORD")
keyAlias = System.getenv("AR_KEY_ALIAS")
keyPassword = System.getenv("AR_KEY_PASSWORD")
} else {
keyAlias = keystoreProperties["keyAlias"] as String?
keyPassword = keystoreProperties["keyPassword"] as String?
storeFile = (keystoreProperties["storeFile"] as String?)?.let { file(it) }
storePassword = keystoreProperties["storePassword"] as String?
}
}
}
buildTypes {
getByName("release") {
signingConfig = signingConfigs.getByName("release")
}
}
}android {
signingConfigs {
release {
if (System.getenv()["CI"]) {
storeFile file(System.getenv()["AR_KEYSTORE_PATH"])
storePassword System.getenv()["AR_KEYSTORE_PASSWORD"]
keyAlias System.getenv()["AR_KEY_ALIAS"]
keyPassword System.getenv()["AR_KEY_PASSWORD"]
} else {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
storePassword keystoreProperties['storePassword']
}
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
}Checking the signature
If Google Play rejects an upload with "your Android App Bundle is signed with the wrong key", compare fingerprints. The one Google expects is shown under Setup → App signing → Upload key certificate; the one you used:
keytool -list -v -keystore upload.keystore -alias upload | grep SHA1