How to Generate App Bundle in Flutter for Android
To generate an Android App Bundle in Flutter, run the command
flutter build appbundle in your project directory. This creates a .aab file in the build/app/outputs/bundle/release/ folder, ready for Play Store upload.Syntax
The basic command to generate an Android App Bundle in Flutter is:
flutter build appbundle: Builds the app bundle for release.- You can add
--releaseexplicitly, but it is the default. - Use
--target-platformto specify CPU architectures if needed.
bash
flutter build appbundle [--release] [--target-platform=android-arm,android-arm64,android-x64]
Example
This example shows how to generate a release app bundle for all supported Android platforms.
bash
flutter build appbundle --release
Output
Built build/app/outputs/bundle/release/app-release.aab (12.3MB).
Common Pitfalls
Common mistakes when generating app bundles include:
- Not setting the
minSdkVersioninandroid/app/build.gradleto at least 21. - Forgetting to sign the app with a release key, which is required for Play Store uploads.
- Running
flutter build apkinstead offlutter build appbundlewhen an app bundle is needed. - Not cleaning the build folder before rebuilding, which can cause stale builds.
bash
Wrong: flutter build apk --release Right: flutter build appbundle --release
Quick Reference
Summary tips for generating Flutter app bundles:
- Use
flutter build appbundleto create .aab files. - Ensure your app is signed with a release key in
key.propertiesandbuild.gradle. - Check
minSdkVersionis 21 or higher. - Upload the generated .aab file from
build/app/outputs/bundle/release/to Google Play Console.
Key Takeaways
Run
flutter build appbundle to generate the Android App Bundle (.aab) file.Make sure your app is signed with a release key before building the app bundle.
Set
minSdkVersion to 21 or higher in your Android build configuration.Upload the generated .aab file from the build outputs folder to the Google Play Console.
Avoid using
flutter build apk when you need an app bundle for Play Store.