text
stringlengths
1
474
For example, you might have one flavor for your full-fledged production app,
another as a limited “free” app, another for testing experimental features, and so on.Say you want to make both free and paid versions of your Flutter app.
You can use flavors to set up both app versions
without writing two separate apps.
For example, the free version of the app has basic functionality and ads.
In contrast, the paid version has basic app functionality, extra features,
different styles for paid users, and no ads.You also might use flavors for feature development.
If you’ve built a new feature and want to try it out,
you could set up a flavor to test it out.
Your production code remains unaffected
until you’re ready to deploy your new feature.Flavors let you define compile-time configurations
and set parameters that are read at runtime to customize
your app’s behavior.This document guides you through setting up Flutter flavors for iOS, macOS, and Android.<topic_end>
<topic_start>
Environment set up
Prerequisites:To set up flavors in iOS and macOS, you’ll define build configurations in Xcode.<topic_end>
<topic_start>
Creating flavors in iOS and macOS
Open your project in Xcode.Select Product > Scheme > New Scheme from the menu to
add a new Scheme.Duplicate the build configurations to differentiate between the
default configurations that are already available and the new configurations
for the free scheme.info Note
Your configurations should be based on your Debug.xconfig or Release.xcconfig
file, not the Pods-Runner.xcconfigs. You can check this by expanding the configuration names.To match the free flavor, add -free
at the end of each new configuration name.Change the free scheme to match the build configurations already created.<topic_end>
<topic_start>
Using flavors in iOS and macOS
Now that you’ve set up your free flavor,
you can, for example, add different product bundle identifiers per flavor.
A bundle identifier uniquely identifies your application.
In this example, we set the Debug-free value to equal
com.flavor-test.free.Change the app bundle identifier to differentiate between schemes.
In Product Bundle Identifier, append .free to each -free scheme value.In the Build Settings, set the Product Name value to match each flavor.
For example, add Debug Free.Add the display name to Info.plist. Update the Bundle Display Name
value to $(PRODUCT_NAME).Now you have set up your flavor by making a free scheme
in Xcode and setting the build configurations for that scheme.For more information, skip to the Launching your app flavors
section at the end of this document.<topic_end>
<topic_start>
Plugin configurations
If your app uses a Flutter plugin, you need to update
ios/Podfile (if developing for iOS) and macos/Podfile (if developing for macOS).<topic_end>
<topic_start>
Using flavors in Android
Setting up flavors in Android can be done in your project’s
build.gradle file.Inside your Flutter project,
navigate to android/app/build.gradle.Create a flavorDimension to group your added product flavors.
Gradle doesn’t combine product flavors that share the same dimension.Add a productFlavors object with the desired flavors along
with values for dimension, resValue,
and applicationId or applicationIdSuffix.<topic_end>
<topic_start>
Setting up launch configurations
Next, add a launch.json file; this allows you to run the command
flutter run --flavor [environment name].In VSCode, set up the launch configurations as follows:You can now run the terminal command
flutter run --flavor free or you can set up a run
configuration in your IDE.<topic_end>
<topic_start>
Launching your app flavors
For examples of build flavors for iOS, macOS, and Android,
check out the integration test samples in the Flutter repo.<topic_end>
<topic_start>
Retrieving your app’s flavor at runtime
From your Dart code, you can use the appFlavor API to determine what
flavor your app was built with.<topic_end>
<topic_start>
Conditionally bundling assets based on flavor
If you aren’t familiar with how to add assets to your app, see
Adding assets and images.If you have assets that are only used in a specific flavor in your app, you can
configure them to only be bundled into your app when building for that flavor.
This prevents your app bundle size from being bloated by unused assets.Here is an example:In this example, files within the assets/common/ directory will always be bundled
when app is built during flutter run or flutter build. Files within the
assets/free/ directory are bundled only when the --flavor option is set
to free. Similarly, files within the assets/premium directory are
bundled only if --flavor is set to premium.<topic_end>
<topic_start>
More information
For more information on creating and using flavors, check out
the following resources:<topic_end>
<topic_start>
Packages
For packages that support creating flavors, check out the following:
<topic_end>
<topic_start>Build and release an Android app
During a typical development cycle,
you test an app using flutter run at the command line,
or by using the Run and Debug
options in your IDE. By default,
Flutter builds a debug version of your app.When you’re ready to prepare a release version of your app,
for example to publish to the Google Play Store,
this page can help. Before publishing,
you might want to put some finishing touches on your app.
This page covers the following topics:info Note
Throughout this page, [project] refers to
the directory that your application is in. While following
these instructions, substitute [project] with
your app’s directory.<topic_end>
<topic_start>
Adding a launcher icon
When a new Flutter app is created, it has a default launcher icon.
To customize this icon, you might want to check out the
flutter_launcher_icons package.Alternatively, you can do it manually using the following steps:Review the Material Design product