Overview
Building for Android production creates either:- APK (Android Package) - Direct installation file
- AAB (Android App Bundle) - Recommended for Google Play Store
Prerequisites
1
Generate signing key
Create a keystore file for signing your app:Keep this file secure and never commit it to version control.
2
Configure signing
Edit Add to
android/gradle.properties:android/gradle.properties
.gitignore:.gitignore
3
Update build.gradle
Edit
android/app/build.gradle:android/app/build.gradle
Building APK
Debug APK
For testing purposes:android/app/build/outputs/apk/debug/app-debug.apk
Release APK
For production distribution:android/app/build/outputs/apk/release/app-release.apk
Install APK on Device
Building AAB (App Bundle)
Release AAB
Recommended for Google Play Store:android/app/build/outputs/bundle/release/app-release.aab
AAB files are uploaded to Google Play Store, which then generates optimized APKs for each device configuration.
Test AAB Locally
Usebundletool to test AAB files:
Build Variants
Custom Build Types
Define custom build types inandroid/app/build.gradle:
android/app/build.gradle
Build Specific Variant
Product Flavors
Create different app versions (e.g., free/paid):android/app/build.gradle
Optimization
Enable Proguard
Minify and obfuscate code inandroid/app/build.gradle:
android/app/build.gradle
Proguard Rules
Add toandroid/app/proguard-rules.pro:
android/app/proguard-rules.pro
Enable App Bundle Optimization
android/app/build.gradle
Separate APKs per Architecture
android/app/build.gradle
app-armeabi-v7a-release.apkapp-arm64-v8a-release.apkapp-x86-release.apkapp-x86_64-release.apkapp-universal-release.apk
Version Management
Update Version
Editandroid/app/build.gradle:
android/app/build.gradle
- versionCode - Integer, must increment with each release
- versionName - String, user-facing version (e.g., “1.1.0”)
Automate Version Bumping
Use Gradle task:android/app/build.gradle
Gradle Commands
Clean Build
Build All Variants
List Tasks
Verbose Output
Offline Build
Continuous Integration
GitHub Actions
.github/workflows/android.yml
Troubleshooting
Build Failed - Out of Memory
Error:OutOfMemoryError: Java heap space
Solution:
Edit android/gradle.properties:
Missing Keystore
Error:Keystore file not found
Solution:
Ensure keystore path in gradle.properties is correct:
Proguard Crashes App
Solution: Add keep rules for packages causing issues inproguard-rules.pro:
Duplicate Resources
Error:Duplicate resources
Solution:
android/app/build.gradle
Security Best Practices
Secure Keystore Storage
Secure Keystore Storage
- Never commit keystores to version control
- Use CI/CD secrets for automated builds
- Keep separate keystores for debug and release
- Back up keystores securely (losing them means you can’t update your app)
Environment Variables
Environment Variables
Use environment variables for sensitive data:
Enable R8/ProGuard
Enable R8/ProGuard
Always enable code shrinking and obfuscation for release builds to protect your source code.
Next Steps
Run Android
Run and test your app on Android
Publishing Guide
Learn how to publish to Google Play Store
Android Logs
Debug with Android logs
App Signing
Complete guide to app signing