Sub topic 3
Giving each flavor its own name, ID and icon
This chapter assumes you have a Flutter project with android/ and ios/ folders, that you already pass values with --dart-define, and that you know what an application ID (Android) or bundle ID (iOS) is. Each flavor needs its own identity so that the dev and prod apps can install side by side on one device.
Android: application ID, name and icon
The applicationIdSuffix and resValue settings in the productFlavors block give the dev flavor its own ID and display name. For the icon, place a launcher image in android/app/src/dev/res/mipmap-*/ic_launcher.png. Gradle uses files from the flavor folder in place of the matching files in src/main for that flavor only.
Per-flavor Firebase and service config files
Each flavor needs its own backend configuration. Put google-services.json in android/app/src/dev/ and in android/app/src/prod/, so Gradle picks the right file for each build. On iOS, keep one GoogleService-Info.plist per flavor and copy the correct one in a build phase script that reads the scheme name.
Why compile-time values are not secrets
Values passed with --dart-define are compiled into the app binary. Anyone can extract strings from an APK or IPA with standard tools. Treat every value in config/*.json as public. Keep API keys with write access, signing keys and passwords on a server, and have the app request short-lived tokens.
> Not a quote: use a callout instead.
Running flavors from the IDE and CI
In VS Code or Android Studio, create one launch configuration per flavor. Each one passes --flavor, -t and --dart-define-from-file. In CI, generate the config file from the CI secret store, then build:
flutter build apk --release --flavor prod -t lib/main_prod.dart --dart-define-from-file=config/prod.jsonSigning and releasing each flavor
Use the same signing config for all flavors unless the stores require otherwise. Keep the upload keystore out of the repository, and load its path and passwords from environment variables or the CI secret store.
Testing against different configurations
Pass the same define file to tests so they read the settings the app will use:
flutter test --dart-define-from-file=config/dev.jsonExercise
Why does the dev flavor need its own applicationIdSuffix when dev and prod are installed on the same test phone?
Show answer
Android identifies apps by application ID. Without a distinct suffix, the second install replaces the first, so both builds would conflict.