Set up Flutter flavors for Android
This guide shows you how to create Flutter flavors for an Android app.
Overview
#A Flutter flavor when used with Android represents a unified term for various platform-specific features. For example, a flavor could determine which icon, app name, API key, feature flag, and logging level is associated with a specific version of your app.
If you want to create Flutter flavors for an Android app, you can do this in Flutter. In Android, a Flutter flavor is referred to as a product flavor.
The following illustrates an example of the Android build variants that are created when an Android app has two product flavors (staging
, production
) and two build types (debug
, release
):
Product flavors | Build types | Resulting build variants |
---|---|---|
staging | debug | stagingDebug stagingRelease |
production | release | productionDebug productionRelease |
Configure your product flavors
#Complete the following steps to add two Android product flavors called staging
and production
to a new Flutter project called flavors_example
, and then test your project to make sure that the flavors work as expected.
Create a new Flutter project called
flavors_example
with Kotlin as the preferred Android language. By default, the project includes thedebug
andrelease
Android build types.consoleflutter create --android-language kotlin flavors_example
Add the product flavors called
staging
andproduction
to theflavors_example
project.In the
flavors_example
project, navigate to theandroid/app/
directory and openbuild.gradle.kts
.Add the
flavorsDimension
property and theproductFlavors
properties inside of theandroid {} block
. Make sure that theandroid {}
block also contains the defaultdebug
andrelease
build types:build.gradle.ktskotlinandroid { ... buildTypes { getByName("debug") {...} getByName("release") {...} } ... flavorDimensions += "default" productFlavors { create("staging") { dimension = "default" applicationIdSuffix = ".staging" } create("production") { dimension = "default" applicationIdSuffix = ".production" } } }
To make sure that you've set up everything correctly, run your app on the Android product flavors. You won't see any differences because the configuration settings haven't changed, but you do want to make sure that the app can run.
Start an Android emulator or connect a physical device with developer options enabled.
In the console, navigate to the
flavors_example
directory and enter the following command to test thestaging
flavor:consoleflutter run --flavor staging
Repeat the previous step for the
production
flavor.
If everything runs, you're ready to customize your configurations. For more information, see Customize configurations.
Launch a flavor
#After you've created the product flavors for an Android app, you can launch a specific product flavor through Flutter.
You can launch a product flavor with the Flutter CLI using the following steps:
Start an Android emulator or connect a physical device with developer options enabled.
In the console, navigate to the
flavors_example
directory and enter the following command:consoleflutter (run | build) --flavor <flavor_name>
(run | build)
: Replace this with one of the following:run
: Run the app in debug mode.build
: Run the app in production mode.
<flavor_name>
: Replace this with the name of your Android product flavor (for example,staging
orproduction
).
Example:
consoleflutter run --flavor staging
Customize configurations
#After you've added product flavors, you can customize them for your Android app.
Create a distinct app display name
#If you have multiple product flavors, a distinct app name can quickly identify which flavor your deployed app is using.
The following steps show how to add distinct app display names for two product flavors called staging
and production
in a project called flavors_example
.
Update
build.gradle.kts
in your IDE:In the
flavors_example
project, navigate to theandroid/app/
directory and openbuild.gradle.kts
.In the
flavorsDimension
block, add aresValue()
property calledapp_name
to thestaging
andproduction
flavors:build.gradle.ktskotlinandroid { ... flavorDimensions += "default" productFlavors { create("staging") { dimension = "default" resValue( type = "string", name = "app_name", value = "Flavors staging") applicationIdSuffix = ".staging" } create("production") { dimension = "default" resValue( type = "string", name = "app_name", value = "Flavors production") applicationIdSuffix = ".production" } }
Update
AndroidManifest.xml
in your IDE:In the
flavors_example
project, navigate toandroid/app/src/main
and openAndroidManifest.xml
.Replace the value for
android:label
with@string/app_name
.AndroidManifest.xmlxml<manifest xmlns:android="http://schemas.android.com/apk/res/android"> <application android:label="@string/app_name" ... /> />
Launch the app for each product flavor (
staging
,production
) and check to make sure that the app display name has changed for each.To launch a product flavor, see the steps in Launch a flavor.
In the Android App Emulator, go to the list of apps. You should see one for
Flavors p...
andFlavors s...
.To see more information for
Flavors p...
orFlavors s...
, long-press the icon for one of them and and selectApp info
.
Create distinct icons
#If you have multiple product flavors, a distinct icon for each configuration can help you quickly identify which flavor your deployed app is using.
The following steps show how to add a distinct icon for two product flavors called staging
and production
in a project called flavors_example
.
Prepare your icons:
Design your
staging
icon andproduction
icon in the design tool of your choice.Generate versions of the
staging
icon andproduction
icon in the following sizes and them inPNG
format:- mipmap-mdpi (48x48 pixels)
- mipmap-hdpi (72x72 pixels)
- mipmap-xhdpi (96x96 pixels)
- mipmap-xxhdpi (144x144 pixels)
- mipmap-xxxhdpi (192x192 pixels)
Create flavor-specific resource directories:
Navigate to the
android/app/src
directory.Create a directory called
staging/res
.Navigate to the
staging/res
directory.Create the following
mipmap
directories and move the versions of thestaging
icon into them:mipmap-mdpi/48x48_staging.png
mipmap-hdpi/72x72_staging.png
mipmap-xhdpi/96x96_staging.png
mipmap-xxhdpi/144x144_staging.png
mipmap-xxxhdpi/192x192_staging.png
Repeat the previous steps for the
production
flavor directories and icons.Rename all of the icons to
ic_launcher.png
.
Double-check the configurations in
AndroidManifest.xml
in your IDE:In the
flavors_example
project, navigate toandroid/app/src/main
and openAndroidManifest.xml
.Make sure that the value for
android:icon
is@mipmap/ic_launcher
.
Launch the app for each product flavor (
staging
,production
) and check to make sure that the app icon has changed for each. To launch a product flavor, see the steps in Launch a flavor.
Add unique build settings
#If you have additional build settings that you would like to configure for a specific Android product flavor, see Android's Configure build variants.
More information
#For more information on creating and using flavors, check out the following resources:
- Build flavors in Flutter (Android and iOS) with Firebase
- How to Setup Flutter & Firebase with Multiple Flavors using the FlutterFire CLI
Unless stated otherwise, the documentation on this site reflects the latest stable version of Flutter. Page last updated on 2025-03-03. View source or report an issue.