To add a new flavor, you need to open android/app/build.gradle file
and find the following code:
flavorDimensions "release-type"
productFlavors {
dev {
dimension "release-type"
applicationIdSuffix ".dev"
versionNameSuffix "-dev"
}
prod {
dimension "release-type"
}
}You have to add your custom flavor to the productFlavors section.
For example:
flavorDimensions "release-type"
productFlavors {
dev {
dimension "release-type"
applicationIdSuffix ".dev"
versionNameSuffix "-dev"
}
prod {
dimension "release-type"
}
}You also can create directory for your flavor in android/app/src directory.
For example, if you have files that are used only in your flavor (e.g. launch icons, splash, app
name, etc), you can create directory dev in android/app/src and put your files there.
-
Open
Runner.xcworkspacein Xcode. -
Create a new configuration file in
ios/Flutterand name it after your flavor name:
Make sure that you have
Runnertarget selected and your file will be placed inFlutterfolder:
-
Paste the following code into your configuration file:
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.dev.xcconfig"
#include "Generated.xcconfig"
#include "common.xcconfig"
app_icon_suffix=-dev
bundle_suffix=.dev
IDENTIFIER=$(identifier)$(bundle_suffix)
APP_ICON=$(app_icon)$(app_icon_suffix)
Replace
devwith your flavor name.
-
Go to
Runner -> Project -> Runner -> Infoand duplicate configurations (Debug, Release, Profile (if you need it)) for your new flavor. Postfix for your new configuration should be the same as your flavor name. In our case it isdev. So, we'll haveDebug-dev,Release-dev. You also should set correct configuration files for each of your new configuration. In the end you should have something like this:
-
Go to
Product -> Scheme -> New scheme...and create new scheme named after your flavor. Make sure that you haveRunnertarget selected. In the end you should have something like this:
-
Go to
Product -> Scheme -> Edit scheme...and select correct Build Configuration for each of scheme:
You also can specify different icons for each flavor. To do this, you need to create
file flutter_launcher_icons-{your_flavor_name}.yaml. E.g. flutter_launcher_icons-dev.yaml. Then
you can specify path to images, colors and other options for your flavor (
read more about configuration).
Finally, you need to run this command:
dart run flutter_launcher_iconsVSCode:
Open .vscode/launch.json and add the following code:
{
"name": "Run dev",
"request": "launch",
"type": "dart",
"args": [
"--flavor",
"dev"
]
}Now you can launch app with dev flavor by clicking on Run dev in debug tab:
Android Studio:
Open Run/Debug Configurations and add new Flutter configuration. In Build flavor field
add dev:
After configuring flavors, you can set different app names for each build.
- Open
android/app/build.gradlefile and find the following code:
flavorDimensions "release-type"
productFlavors {
dev {
dimension "release-type"
applicationIdSuffix ".dev"
versionNameSuffix "-dev"
}
prod {
dimension "release-type"
}
}- Add a res value, which will store the app name. Example:
flavorDimensions "release-type"
productFlavors {
dev {
dimension "release-type"
applicationIdSuffix ".dev"
versionNameSuffix "-dev"
resValue "string", "app_name", "My App Dev"
}
prod {
dimension "release-type"
resValue "string", "app_name", "My App"
}
}- Open
android/app/src/main/AndroidManifest.xmland find the following code:
<application
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name">- For android:label, set the value to "@string/app_name"
- Open the ios module in Xcode
- Select your target and then "Build Settings". Press "+" and select "Add Custom Setting".
- Add a new User-Defined setting, such as APP_DISPLAY_NAME. In this variable, you should enter the names of your application for different assemblies.
- In info.plist, set the Bundle name value to ${APP_DISPLAY_NAME}

