Expert: features and shipping · Publishing on the Play Store and Firebase · topic 43 of 50 · 35 min
Release builds, signing and the App Bundle
Explanation
Debug versus release
While developing, you run debug builds: easy to debug, not optimised, signed with an automatic debug key. What you give to users is a release build: optimised, shrunk, and signed with your own key. Never upload a debug build.
R8: shrinking and obfuscation
R8 is the tool that optimises release builds. It removes unused code (shrinking), shortens names (obfuscation, which also makes reverse engineering a little harder) and optimises the remaining code. Resource shrinking removes unused images and layouts. Together they make the app smaller and faster.
android {
buildTypes {
release {
isMinifyEnabled = true
isShrinkResources = true
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro",
)
}
}
}Signing and keys
Android only installs apps that are digitally signed. A signature proves who made the app and that it was not changed. Updates must be signed by the same key, or Android refuses to install them over the old version. A keystore is a password-protected file that holds keys.
| Key | Who holds it | Used for |
|---|---|---|
| Upload key | You (in your keystore) | Signing the bundles you upload to Play Console |
| App signing key | Google, with Play App Signing | Signing the APKs that users actually install |
With Play App Signing (required for new apps), losing your upload key is recoverable: you can ask Google support to reset it. Still, guard it carefully: back up the keystore file and passwords somewhere safe and private, and never commit them to Git or share them in chat.
Building a signed bundle
- In Android Studio: Build > Generate Signed App Bundle or APK, choose Android App Bundle.
- Create a new keystore the first time (choose a strong password and remember the key alias), or select your existing one.
- Choose the release build variant and finish. The .aab file appears in app/release/.
./gradlew bundleReleaseWhy an App Bundle?
An APK is the installable package. An Android App Bundle (.aab) is a publishing format that contains all your code and resources. Google Play uses it to generate optimised APKs for each device, with only the screen density, CPU type and languages that phone needs. Users download less, which matters on slow or expensive mobile data. New apps on Google Play must be published as AABs (required since August 2021).
Versioning
versionCode is an integer that must increase for every upload; Play Console rejects a bundle whose versionCode it has already seen. versionName ("1.2.0") is the friendly version users see. A common habit is to bump versionCode by one for each release and follow MAJOR.MINOR.PATCH for versionName.
Common mistakes
- Committing the keystore or its passwords to GitHub. Add them to .gitignore and store them privately.
- Forgetting to increase versionCode: "Version code 3 has already been used".
- Not testing the release build: R8 can remove classes used by reflection, causing crashes only in release.
- Uploading an APK for a new app: Play requires an AAB.
Need help?
Stuck on a word or an idea? Search this course, or every course, and jump straight to the explanation or a worked question.
Try:
Watch the lesson
Release builds, signing and the App Bundle · 1/7
Users get release builds: optimised, shrunk and signed with your key. Never upload a debug build.
Prefer a video by a teacher? Find free videos on “android generate signed app bundle play app signing release build r8” on YouTube ↗
In real life: The first release of a tiffin service app
A home-food delivery startup prepares version 1.0 of its app. The developer enables R8, builds a release bundle on a real phone and finds one crash caused by a JSON model stripped by R8, fixed with a keep rule. She creates the upload keystore, stores it and its passwords in the company password manager with a backup, and uploads the signed .aab with versionCode 1. The app drops from 18 MB (debug) to about 7 MB download size.
android {
defaultConfig {
versionCode = 1
versionName = "1.0.0"
}
}Practice (0/3 done)
Play Console says "Version code 5 has already been used". What should you do?
Which format must new apps use on Google Play?
For one of your apps: enable R8 and resource shrinking, generate a signed App Bundle with a new upload keystore, install a release build on your phone (for example by building a signed release APK for local testing) and test every screen. Write down where you stored the keystore backup (without the passwords).
Quick quiz
Read more (free)
Related help
Before this, learn
This topic builds on these. If something here feels new, open them first.
Related topics
- Google Play Console and testing tracksPublishing on the Play Store and Firebase · same module
- Play policies: privacy, data safety and targetsPublishing on the Play Store and Firebase · same module
- Firebase basicsPublishing on the Play Store and Firebase · same module
- Publishing on Google PlayFlutter and Dart · Publishing to the stores and the web
- Preparing a releaseFlutter and Dart · Publishing to the stores and the web
- Interview questions: Android and ComposeAndroid career path
Questions people ask about this
Open a question to see the answer and why. The first ones are this topic's own quiz, so try the quiz above before you peek.
What does R8 do?
Answer: Shrinks, obfuscates and optimises release code
R8 is the release optimiser.
With Play App Signing, who holds the app signing key?
Answer: Google
You keep the upload key; Google keeps the app signing key.
Why must updates be signed with the same key as the original app?
Answer: Android only accepts updates from the same signer, which proves they come from you
The signature is the app's identity.
What is the benefit of an App Bundle for users?
Answer: Smaller downloads tailored to their device
Play delivers only what each device needs.
With Play App Signing, which key do you keep?Related
Does obfuscation keep API keys in the app safe?Related
Answer: No; secrets in an app can still be extracted
Keep secrets on the server.
From Preparing a release
What do reviewers most often check first in a take-home Android app?Related
Answer: Whether it runs, handles states and rotation, and has clean structure
Working basics and clean structure matter most.
Where do you explain why the app needs the camera on iOS?Related
Answer: A usage description key in Info.plist
For example NSCameraUsageDescription.
Pass the quiz (60% or more) or mark this topic as done when you are ready.
Your progress is saved on this device only.
Next steps
- 3 more topics in “Publishing on the Play Store and Firebase” before its exam: Google Play Console and testing tracks, Play policies: privacy, data safety and targets, Firebase basics.
- Module 11 exam: Publishing on the Play Store and Firebase · 13 questions · 25 min, without help. 4 topics of this module still to finish first.
- Then the next module, Android career path. 50 topics left in the course before the final exam.