Sub topic 9
Giving each flavor its own name, ID and icon
Assume you already know basic Flutter development, can run flutter run and flutter build, and understand the android/ and ios/ project folders. This chapter focuses on native identity: how users and app stores distinguish dev, staging, and production builds.
A flavor should usually have its own:
- Display name, such as
MyApp Dev - Application ID on Android
- Bundle identifier on iOS
- Launcher icon
- Service configuration, such as a Firebase file
These values let you install a development build beside the production build instead of replacing it.
Android application IDs and names
Android identifies an installed application with its application ID. A suffix gives a flavor a separate identity while keeping most configuration shared.
In android/app/build.gradle.kts, define the flavors inside the android block:
android {
flavorDimensions += "env"
productFlavors {
create("dev") {
dimension = "env"
applicationIdSuffix = ".dev"
resValue("string", "app_name", "MyApp Dev")
}
create("prod") {
dimension = "env"
resValue("string", "app_name", "MyApp")
}
}
}The production application ID might be com.example.myapp. The dev application ID becomes com.example.myapp.dev. Android can therefore install both applications.
Set the application label in android/app/src/main/AndroidManifest.xml:
<application
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher">
</application>resValue creates the app_name resource for each flavor. The manifest reads the correct value when Gradle builds that flavor.
Android combines a flavor name with a build type. Common variants include:
| Flavor | Build type | Variant |
|---|---|---|
| dev | debug | devDebug |
| dev | release | devRelease |
| prod | release | prodRelease |
Per-flavor launcher icons
Android resources can be flavor-specific. For example, place development launcher resources under:
android/app/src/dev/res/mipmap-hdpi/
android/app/src/dev/res/mipmap-mdpi/
android/app/src/dev/res/mipmap-xhdpi/Place production resources under matching directories beneath src/prod/res/. Gradle selects resources from the active flavor. A dev build can show a colored or marked icon, making it harder to confuse with production.
Keep the same resource names, such as ic_launcher, in each flavor. The manifest then stays unchanged while the selected resource changes.
iOS bundle identifiers and icons
iOS uses a bundle identifier for the same purpose. Configure a different identifier for each scheme and build configuration, for example:
| Scheme | Bundle identifier | Display name |
|---|---|---|
| Dev | `com.example.myapp.dev` | `MyApp Dev` |
| Prod | `com.example.myapp` | `MyApp` |
In Xcode, create schemes named Dev and Prod. Each scheme should select matching build configurations, such as Debug-Dev and Release-Prod.
Set these build settings per configuration:
PRODUCT_BUNDLE_IDENTIFIER: the bundle identifierPRODUCT_NAMEorINFOPLIST_KEY_CFBundleDisplayName: the visible nameASSETCATALOG_COMPILER_APPICON_NAME: the app icon set
Create separate icon sets in ios/Runner/Assets.xcassets, such as AppIcon-Dev and AppIcon-Prod. Select the appropriate icon set in each configuration. The scheme determines which settings Xcode uses.
Avoiding identity mistakes
Check the generated artifact before distribution. A production build with a dev identifier can appear as a separate app in testing. A dev build with the production identifier can replace a user's production app.
Keep the naming scheme consistent across Dart configuration, Android flavors, iOS schemes, CI jobs, and service files. For example, use dev, staging, and prod everywhere rather than mixing development, stage, and production.
Exercise
Why does a dev build need a different Android application ID or iOS bundle identifier from production?
Show answer
The operating system uses that identifier to distinguish installed applications. A different identifier lets both builds remain installed at the same time.