flutter build: APK, App Bundle, and iOS in CI
flutter build <target> compiles a release artifact: apk and appbundle for Android, ios and ipa for iOS.
flutter build wraps the underlying Gradle and Xcode toolchains, so its failures usually surface those tools underneath. Knowing which flags pass through (flavor, dart-define, build-number) keeps release builds reproducible.
What it does
flutter build produces a release-mode artifact for the named target. It runs pub get, compiles Dart to native, and invokes Gradle (Android) or Xcode (iOS) to package. --release is the default for build; flavors, dart-defines, and version overrides pass through to the platform build.
Common usage
flutter build apk --release
flutter build appbundle --release --flavor prod
flutter build ipa --export-options-plist=ExportOptions.plist
flutter build ios --release --no-codesign # CI without signing
flutter build apk --dart-define=API_URL=https://api.example.comOptions
| Target / flag | What it does |
|---|---|
| apk / appbundle | Android APK or .aab |
| ios / ipa | iOS app or signed .ipa archive |
| --release / --debug / --profile | Build mode |
| --flavor <name> | Build a specific product flavor / scheme |
| --dart-define=<K>=<V> | Pass a compile-time constant |
| --no-codesign | Build iOS without code signing (CI compile check) |
| --build-number / --build-name | Override versionCode / versionName |
In CI
Run flutter build ios --no-codesign for a compile-only check when signing certs are not available, and do the signed archive with xcodebuild or fastlane separately. Provide the Android keystore from a secret and reference it in key.properties. Cache the pub and Gradle caches between runs.
Common errors in CI
"Gradle task assembleRelease failed with exit code 1" wraps an underlying Gradle failure; scroll up for the real cause (often a missing keystore or an unaccepted SDK license). "CocoaPods not installed or not in valid state" on iOS means pod install has not run in ios/; run it. "Command PhaseScriptExecution failed" points at an Xcode run-script phase. "No valid code signing certificates were found" means missing iOS signing setup.