Sub topic 12
Running flavors from the IDE and CI
This chapter assumes basic Dart and Flutter development, familiarity with android/ and ios/, and experience running flutter run and flutter build. You also need the environment setup from earlier chapters: named entrypoints, native flavors or schemes, and configuration files such as config/dev.json.
Configure an IDE launch
An IDE launch configuration is a saved set of Flutter command-line arguments. It prevents developers from forgetting an entrypoint, flavor, or configuration file.
For Visual Studio Code, create .vscode/launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "MyApp Dev",
"request": "launch",
"type": "dart",
"program": "lib/main_dev.dart",
"args": [
"--flavor",
"dev",
"--dart-define-from-file=config/dev.json"
]
},
{
"name": "MyApp Prod",
"request": "launch",
"type": "dart",
"program": "lib/main_prod.dart",
"args": [
"--flavor",
"prod",
"--dart-define-from-file=config/prod.json"
]
}
]
}Select MyApp Dev or MyApp Prod from the Run and Debug menu. The program value selects the Dart entrypoint. The --flavor value selects the native Android flavor or iOS scheme. The configuration file supplies compile-time values to AppConfig.
Android Studio and IntelliJ use Flutter run configurations. Create one configuration for each environment, then set its Dart entrypoint, Build flavor, and Additional run args to the equivalent values.
Make CI builds explicit
Continuous integration (CI) is an automated build system that runs on a server. CI should use explicit commands rather than relying on a developer's IDE settings.
A simple shell job can run the dev app and build a production APK:
set -euo pipefail
flutter pub get
flutter analyze
flutter test --dart-define-from-file=config/dev.json
flutter build apk \
--release \
--flavor prod \
-t lib/main_prod.dart \
--dart-define-from-file=config/prod.jsonThe \ characters continue one command across multiple lines. set -e stops the job after a failure. The test command passes the same kind of configuration that the application uses, while the build command selects the production native flavor.
Use a CI matrix when one job must build several environments:
| Environment | Entrypoint | Native flavor | Configuration |
|---|---|---|---|
| dev | `lib/main_dev.dart` | `dev` | `config/dev.json` |
| prod | `lib/main_prod.dart` | `prod` | `config/prod.json` |
For iOS, use the matching scheme and an export configuration. The exact signing and export options depend on the project, but the environment names should remain consistent:
flutter build ipa \
--release \
--flavor prod \
-t lib/main_prod.dart \
--dart-define-from-file=config/prod.jsonProtect signing certificates, provisioning profiles, and service credentials with the CI provider's secret store. Do not commit them to the repository.
Trace one build from source to app
Verify the selected environment
Read the active flavor with appFlavor when diagnostics need to show which native variant is running. Log it only in development or test builds. Also display a non-secret environment label in a debug screen so a tester can identify the installed app.
Run the same command locally and in CI when possible. This makes failures reproducible and catches missing files, incorrect flavor names, and unsupported signing settings before release day.
Exercise
A CI job builds lib/main_prod.dart but omits --flavor prod. What can go wrong?
Show answer
The Dart code may use production settings while the native project uses its default configuration. The app can receive the wrong name, identifier, assets, or signing settings. Pass the matching flavor or scheme explicitly.