Building and Releasing
|
This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production. |
Shipping Trailhead means producing a signed Android App Bundle and an iOS archive, sending them to Google Play and App Store Connect, and doing it repeatably from CI. The tests from Testing are the gate in front of this pipeline. Deep link verification (see Navigation and Routing) also depends on the signing certificates configured here. For comparison with other stacks see React Native and Kotlin Multiplatform; the overview is in Hybrid Apps.
Build Modes
| Mode | Compilation | Use |
|---|---|---|
Debug ( |
JIT, hot reload, assertions on, debugging service enabled. |
Daily development; slow and large. |
Profile ( |
AOT, with profiling hooks. |
Performance measurements with DevTools on a real device. |
Release ( |
AOT, tree-shaken, optimised, assertions off. |
What users receive. |
Never judge performance in debug mode: the framework is deliberately slower there. Rendering details are in Architecture and Rendering.
Build Commands
flutter build apk --release # a universal APK for sideloading and testing
flutter build appbundle --release # the .aab uploaded to Google Play
flutter build ipa --release # an iOS archive and .ipa (needs macOS and Xcode)
flutter build web --release # optional web target
Outputs appear under build/app/outputs/ for Android and build/ios/ for iOS.
Versioning in pubspec.yaml
name: trailhead
version: 1.4.0+27 # versionName 1.4.0, build number (versionCode) 27
The part before the plus is the user-visible version; the part after is the build number, which must increase with
every upload to a store. Override both at build time with --build-name and --build-number, which is handy in CI
when the build number comes from the run counter.
Flavors and Compile-Time Configuration
Two mechanisms separate environments:
-
Flavors change native configuration: application id, name, icon, signing, and Firebase files. They are defined in Gradle
productFlavorson Android and in Xcode schemes and configurations on iOS, then selected with--flavor staging. -
Dart defines change Dart values at compile time.
flutter run --flavor staging --dart-define=API_BASE_URL=https://staging-api.example.com/v1
flutter build appbundle --flavor production --dart-define-from-file=config/production.json
{
"API_BASE_URL": "https://api.example.com/v1",
"ENABLE_LOGGING": "false"
}
const apiBaseUrl = String.fromEnvironment(
'API_BASE_URL',
defaultValue: 'https://api.example.com/v1',
);
const enableLogging = bool.fromEnvironment('ENABLE_LOGGING');
Values compiled into the app can be extracted by anyone who has the binary, so never put real secrets in them; keep secrets on a server, as discussed in Data, Storage and Networking.
App Icons and Splash Screen
Community packages generate platform assets from one source image: flutter_launcher_icons for icons and
flutter_native_splash for the launch screen. Each reads a configuration block in pubspec.yaml and is run once
with dart run. Check each package’s page for the current options before use.
Android Release
Signing
Create an upload keystore once and keep it out of version control:
keytool -genkey -v -keystore ~/upload-keystore.jks -keyalg RSA -keysize 2048 -validity 10000 -alias upload
# android/key.properties (gitignored)
storePassword=<from a secret store>
keyPassword=<from a secret store>
keyAlias=upload
storeFile=/path/to/upload-keystore.jks
// android/app/build.gradle (excerpt)
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
android {
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
storePassword keystoreProperties['storePassword']
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
}
New projects may use Kotlin DSL (build.gradle.kts) with equivalent settings; follow the files in your project. A
relative storeFile is resolved by file() against the app module, android/app/, not against android/ where
key.properties lives.
iOS Release
-
Enrol in the Apple Developer Program and create the app record in App Store Connect.
-
In Xcode, open
ios/Runner.xcworkspace, set the team and bundle identifier, and enable automatic signing (or configure certificates and provisioning profiles manually for CI). -
Run
flutter build ipa --release, then upload the result with the Xcode Organizer or Apple’s Transporter app. -
The build appears in TestFlight for internal and external testers. After review, submit it for the App Store.
Apple requires privacy strings for every sensitive API used; see Platform Integration.
Obfuscation and Size
Obfuscation renames Dart symbols in the AOT build, and the debug symbols are written to a separate directory that you must keep to read crash reports:
flutter build appbundle --release --obfuscate --split-debug-info=build/symbols
Keep build/symbols for every released build number. To see what contributes to the size, build with --analyze-size
and open the generated JSON in DevTools' app size tool:
flutter build apk --analyze-size
Typical savings come from compressing images, removing unused packages, and restricting fonts and icon sets.
Release Pipeline
CI with GitHub Actions
name: Android release
on:
push:
tags: ['v*']
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: '17'
- uses: subosito/flutter-action@v2
with:
flutter-version: 3.47.9
channel: stable
cache: true
- run: flutter pub get
- run: flutter analyze
- run: flutter test --coverage
- name: Restore keystore
run: |
echo "$KEYSTORE_BASE64" | base64 --decode > android/app/upload-keystore.jks
cat > android/key.properties <<PROPS
storePassword=$STORE_PASSWORD
keyPassword=$KEY_PASSWORD
keyAlias=upload
storeFile=upload-keystore.jks
PROPS
env:
KEYSTORE_BASE64: ${{ secrets.KEYSTORE_BASE64 }}
STORE_PASSWORD: ${{ secrets.STORE_PASSWORD }}
KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }}
- run: flutter build appbundle --release --obfuscate --split-debug-info=build/symbols
- uses: actions/upload-artifact@v4
with:
name: aab
path: build/app/outputs/bundle/release/*.aab
iOS builds need a macOS runner (macos-latest), with the certificate and provisioning profile installed from
secrets before flutter build ipa. Pin the Flutter version, as above, so the build is reproducible.
Fastlane and Shorebird
Fastlane automates uploads to Google Play and TestFlight (lanes written in Ruby), screenshots, and version bumps. It is optional but common in teams that release frequently.
Shorebird is a third-party service for code push: it can deliver Dart code patches to installed apps without a new store submission. It is not part of Flutter, it has its own pricing and terms, and store policies restrict what a patch may change, so evaluate it carefully against the guidelines of each store before adopting it.
Release Checklist
-
Version and build number increased in
pubspec.yaml. -
Release keystore or signing certificate available to CI as secrets, never committed.
-
Obfuscation symbols archived per build.
-
Permissions and privacy strings reviewed.
-
Tested on a real device in release or profile mode.
-
Store listing, screenshots, and privacy declarations ready.
The commands are collected in the Flutter Cheat Sheet.