Sub topic 7
Building an App Bundle and APKs
Assume you know basic Flutter development, can use a terminal, and have configured a release signing key for Android. A signed release configuration is required for artifacts that you plan to publish or distribute outside development.
Choose the right Android artifact
Android apps can be distributed in two common formats:
| Artifact | Main use | Important property |
|---|---|---|
| App Bundle (`.aab`) | Google Play | Google Play creates optimized APKs for each device |
| APK (`.apk`) | Direct installation and testing | You install the file directly on a device |
An Android App Bundle is usually the correct upload format for Google Play. It contains your app's compiled code and resources, but Google Play generates device-specific APKs from it. This reduces download size for users.
An APK is useful when you need to install an app yourself, send it to a tester, or distribute it through a service that accepts APK files.
Build an App Bundle
From the root of your Flutter project, run:
flutter build appbundle --releaseThe --release option selects Flutter's release build mode. Release mode removes development tooling and applies optimizations intended for users.
The bundle is normally written to:
build/app/outputs/bundle/release/app-release.aabThe exact path can vary slightly with the Android Gradle Plugin version, so check the command output if you need to locate the file.
Before running this command for a store upload, check these values:
- The application ID identifies the Android package, such as
com.example.my_app. - The version name is shown to users.
- The version code is an integer that must increase for every Google Play upload.
- The release build type uses your upload signing configuration.
- The app has the correct launcher icon and display name.
If the application ID or signing configuration is wrong, stop before uploading. Google Play treats an application ID as the identity of an app, and you cannot change it for an existing listing.
Build APKs split by architecture
For direct installation, build one APK for each supported CPU architecture:
flutter build apk --release --split-per-abi--split-per-abi creates separate files for architectures such as ARM 64-bit and ARM 32-bit. Each APK is smaller than one universal APK because it contains native libraries for only one architecture.
The files are normally placed under:
build/app/outputs/flutter-apk/Typical names include:
app-arm64-v8a-release.apk
app-armeabi-v7a-release.apk
app-x86_64-release.apkGive a tester the APK that matches the device. Most current physical Android phones use arm64-v8a. Android emulators commonly use x86_64, although the correct architecture depends on the emulator image.
You can also build one universal APK:
flutter build apk --releaseThis file supports multiple architectures, but it is larger because it includes all selected native libraries.
Understand the build flow
Verify the artifact before upload
Install an APK on a real device before publishing:
flutter install --releaseFor a specific APK, enable installation from your chosen development method and install the file manually. Test startup, navigation, authentication, network access, notifications, deep links, and purchase flows. Release builds can expose problems that debug builds hide, such as missing permissions, incorrect production URLs, or code that depends on debugging behavior.
Exercise
Which command should you normally use for a Google Play upload, and which command creates separate APKs for direct testing?
Show answer
Use flutter build appbundle --release for a Google Play App Bundle. Use flutter build apk --release --split-per-abi to create architecture-specific APKs for direct testing.