Sub topic 9
Giving each flavor its own name, ID and icon
This chapter assumes you have a working --flavor setup from earlier in the tutorial. You should know that a flavor name must match an Android product flavor and an iOS scheme. Here you will make those flavors visibly different on a device: a different app name, a different application ID, and a different launcher icon.
Why identity matters
If dev and prod builds share one application ID, the second install replaces the first. You cannot compare a fix on dev with the behavior of the production app you have installed. They also share local data, push tokens and store listings.
Three values give a build its identity.
| Value | Android | iOS | What it controls |
|---|---|---|---|
| App ID | `applicationId` | `PRODUCT_BUNDLE_IDENTIFIER` | Whether the builds install side by side, and which backend project and store record they map to |
| Display name | `android:label` | `CFBundleDisplayName` | The text under the launcher icon |
| Icon | `mipmap` resources | `AppIcon` asset set | The visual cue that tells testers which build they are opening |
Dart code does not touch any of these. They are native settings, so each platform needs its own configuration, selected by the flavor name.
Android: ID and name in Gradle
The flavor block from the previous chapters already carries the ID and the name:
// android/app/build.gradle.kts, inside the android { } block
flavorDimensions += "env"
productFlavors {
create("dev") {
dimension = "env"
applicationIdSuffix = ".dev"
resValue("string", "app_name", "MyApp Dev")
}
create("prod") {
dimension = "env"
resValue("string", "app_name", "MyApp")
}
}Two mechanisms are at work here.
applicationIdSuffixis appended to theapplicationIdfromdefaultConfig. If the base ID iscom.example.myapp, the dev build installs ascom.example.myapp.dev. The prod flavor sets no suffix, so it keeps the base ID.resValue("string", "app_name", ...)makes Gradle generate a string resource for that flavor only. The manifest refers to it withandroid:label="@string/app_name", so the same manifest produces a different label per flavor.
The duplicate resource error
A resource name can be defined only once per build variant. If android/app/src/main/res/values/strings.xml also contains app_name, the build fails with a duplicate resource error. Delete the app_name entry from strings.xml and let the flavors supply it. If you want a fallback, define it in defaultConfig with resValue instead.
Manifest placeholders as an alternative
Some teams prefer manifestPlaceholders["appName"] = "MyApp Dev" and android:label="${appName}" in the manifest. Both approaches work. Placeholders are only available inside the manifest, while resValue also lets Kotlin or Java code read R.string.app_name. Pick one approach and use it for every flavor.
Android: icons with source sets
Gradle merges the main source set with a source set named after each flavor. Files in the flavor source set override files with the same path in main. You do not change android:icon="@mipmap/ic_launcher" in the manifest. You only add a differently drawn ic_launcher for the flavor.
android/app/src/
main/res/mipmap-hdpi/ic_launcher.png <- used by prod (default)
dev/res/mipmap-hdpi/ic_launcher.png <- overrides it for dev
dev/res/mipmap-mdpi/ic_launcher.png
dev/res/mipmap-xhdpi/ic_launcher.png
dev/res/mipmap-xxhdpi/ic_launcher.png
dev/res/mipmap-xxxhdpi/ic_launcher.pngThe directory name dev must equal the flavor name exactly, including case. Provide every density you provide in main. A missing density falls back to main, so some devices show the production icon and others show the dev icon.
If your icon is an adaptive icon, the same rule applies to mipmap-anydpi-v26/ic_launcher.xml and the foreground and background layers it references. Override all files that differ.
Generating icons
Resizing icons by hand is tedious. The flutter_launcher_icons package can read a configuration file per flavor, such as flutter_launcher_icons-dev.yaml, and write the files into the right places. Run it once per flavor and commit the output. It writes into the same src/<flavor>/res and asset catalog locations described here, so you can still adjust the results manually.
A simple way to make dev builds recognizable is to take the production icon and add a colored banner or a letter. Testers then notice immediately which build they are in.
iOS: build configurations and settings
On iOS the flavor is a scheme, and each scheme uses build configurations named <Mode>-<flavor>. For a flavor dev, Flutter expects Debug-dev, Release-dev and Profile-dev. Per-flavor identity lives in build settings on those configurations.
The cleanest approach is one .xcconfig file per flavor, attached to its configurations in Xcode (Project, Info, Configurations):
// ios/Flutter/dev.xcconfig
#include "Generated.xcconfig"
PRODUCT_BUNDLE_IDENTIFIER = com.example.myapp.dev
APP_DISPLAY_NAME = MyApp Dev
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon-dev// ios/Flutter/prod.xcconfig
#include "Generated.xcconfig"
PRODUCT_BUNDLE_IDENTIFIER = com.example.myapp
APP_DISPLAY_NAME = MyApp
ASSETCATALOG_COMPILER_APPICON_NAME = AppIconThen make Info.plist read the variable, so no name is hard-coded:
<key>CFBundleDisplayName</key>
<string>$(APP_DISPLAY_NAME)</string>For the icon, add a second app icon set named AppIcon-dev to ios/Runner/Assets.xcassets. The ASSETCATALOG_COMPILER_APPICON_NAME build setting tells Xcode which set to compile into the app. Because the setting comes from the configuration, each flavor picks its own set.
Where settings can silently go wrong
- Setting
PRODUCT_BUNDLE_IDENTIFIERon the target for all configurations overrides your xcconfig value. Check in Xcode's Build Settings view with "Levels" shown, and make sure the target does not set a value of its own. - Xcode lists a setting inherited from the project in a different color. If the bundle ID looks right in the editor but wrong on the device, you are probably reading the wrong level.
- If you add
Debug-devby duplicatingDebug, the CocoaPods xcconfig thatpod installlinks may not follow. Runpod installagain and confirm that each new configuration includes the matchingPods-Runner.*.xcconfig. - The scheme must be marked as Shared, otherwise it exists only in your local
xcuserdataand CI cannot find it.
Keeping the platforms consistent
The two platforms do not check each other. Nothing stops you from naming Android com.example.myapp.dev and iOS com.example.myapp-dev. Decide the convention once, write it down, and use a table like this in your project README:
| Flavor | Android application ID | iOS bundle identifier | Display name |
|---|---|---|---|
| dev | `com.example.myapp.dev` | `com.example.myapp.dev` | MyApp Dev |
| staging | `com.example.myapp.staging` | `com.example.myapp.staging` | MyApp Stg |
| prod | `com.example.myapp` | `com.example.myapp` | MyApp |
Keep display names short. Launchers truncate labels at about a dozen characters, so MyApp Development may appear as MyApp Devel….
The ID also decides which entries in other systems apply. Push notification setup, deep link domains, OAuth redirect settings and Firebase app registrations are all tied to the ID. A new suffix means a new registration in each of those systems. The next chapter covers the Firebase part.
Verifying the result
Do not trust the configuration until you have looked at an installed build. Build both flavors and install them on one device:
flutter run --flavor dev -t lib/main_dev.dart --dart-define-from-file=config/dev.json
flutter run --flavor prod -t lib/main_prod.dart --dart-define-from-file=config/prod.jsonThen check these points:
- Both apps appear in the launcher at the same time, each with its own label and icon.
- On Android,
adb shell pm list packages | grep myapplists both application IDs. - Data entered in one app, such as a login, does not appear in the other.
appFlavorprintsdevin one app andprodin the other.
Running both at once is the practical test of everything in this chapter. If the second install replaces the first, the application IDs are still identical.
Common errors
| Symptom | Likely cause |
|---|---|
| Duplicate resources error for `app_name` | `app_name` exists in both `strings.xml` and `resValue` |
| Dev build shows the prod icon on some devices | Flavor icon is missing for some densities |
| Dev install overwrites prod install | Suffix not applied, or the flavor name used for the build differs from the Gradle flavor |
| iOS app shows the wrong name | `CFBundleDisplayName` is hard-coded, or the xcconfig is not attached to the configuration |
| `flutter run` reports no scheme found | Scheme is not shared, or does not match the flavor name |
Exercise
Your Android dev flavor builds, but on a test phone installing it removes the production app. Name two things you would check in build.gradle.kts and one thing you would check on the phone.
Show answer
In build.gradle.kts, check that the dev flavor sets applicationIdSuffix = ".dev", and that the flavor you build (--flavor dev) is the one that has the suffix and not a different flavor block. On the phone, check the installed package names, for example with adb shell pm list packages | grep myapp. If only one package appears after both installs, the IDs are identical.
Exercise
On iOS, the dev scheme builds, but the app still shows the production icon even though AppIcon-dev exists in Assets.xcassets. Which build setting do you check, and where is it configured?
Show answer
Check ASSETCATALOG_COMPILER_APPICON_NAME. It should be AppIcon-dev for the Debug-dev, Release-dev and Profile-dev configurations, usually through the flavor's xcconfig file. If the target sets its own value for this setting, that value overrides the xcconfig, so remove it or check the Levels view in Xcode.