Skip to content

Support for app flavors in flutter tooling (retake)#11734

Merged
mravn-google merged 8 commits intoflutter:masterfrom
mravn-google:flavors
Aug 23, 2017
Merged

Support for app flavors in flutter tooling (retake)#11734
mravn-google merged 8 commits intoflutter:masterfrom
mravn-google:flavors

Conversation

@mravn-google
Copy link
Copy Markdown
Contributor

Retake of #11676, with fixes to make cocoon tests run.

Fixes #11547.

flutter build, flutter run, and flutter drive now understand app "flavors" or "variants". This means that you can build different flavors of your app from the same source code, but with different configuration as defined by platform-specific build settings. Flavors are orthogonal to the existing debug/profile/release build modes:

flutter run --flavor free            # Launch the free app in debug mode
flutter run --flavor paid            # Launch the paid app in debug mode
flutter run --profile --flavor free  # Launch the free app in profile mode
flutter run --profile --flavor paid  # Launch the paid app in profile mode
flutter run --release --flavor free  # Launch the free app in release mode
flutter run --release --flavor paid  # Launch the paid app in release mode

Flavors at the Flutter CLI level map to product flavors in Android projects (with Flutter build modes mapping to Android build types) and to schemes in iOS projects (with Flutter build mode/flavor pairs mapping to Xcode build configurations).

The Android Gradle build tasks corresponding to the above would be

assembleFreeDebug
assemblePaidDebug
assembleFreeProfile
assemblePaidProfile
assembleFreeRelease
assemblePaidRelease

Android makes the flavor available to Java code as BuildConfig.FLAVOR. It can be communicated to the Dart side using platform channels (a convenient plugin for handling this could be built).

For Xcode, one can define build configurations according to a custom naming scheme, e.g.

Debug-Free
Debug-Paid
Release-Free
Release-Paid

---and then map each build configuration to one of two custom schemes named Free and Paid. Each build configuration might include a user-defined Build Setting entry, such as FLAVOR with values free or paid. This value can be exposed to ObjC by adding a Flavor: $(FLAVOR) key/value pair to Info.plist and then accessed using [[NSBundle mainBundle].infoDictionary valueForKey:@"Flavor"]. Flutter tooling does not care about how you set this up, it merely builds the Xcode project specifying the relevant build configuration and scheme.

A sample project using this setup is included for integration testing in dev/integration_tests/flavors. More documentation will be provided in a separate PR.

Copy link
Copy Markdown
Contributor

@szakarias szakarias left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mravn-google mravn-google merged commit 9496e6d into flutter:master Aug 23, 2017
@mravn-google mravn-google deleted the flavors branch November 17, 2017 09:11
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flutter CLI tools should understand build variants

3 participants