Orientação gerada a partir de informações públicas. Apenas para referência.
flutter_flavorizr é uma ferramenta para desenvolvedores que simplifica a criação e gestão de sabores de aplicativos em aplicações Flutter. Ela automatiza a configuração de diferentes variantes de compilação — como desenvolvimento, staging e produção — gerando arquivos específicos para cada plataforma: Android, iOS e macOS. Com pouca configuração inicial, ela agiliza as configurações específicas de ambiente, como nomes do aplicativo, nomes de pacotes, ícones e telas de inicialização. Isso reduz erros manuais e acelera o processo de compilação em múltiplos ambientes.
Casos de uso
Gerenciando múltiplos ambientes de aplicativo
Automatizando a configuração de compilação
Personalizando ativos do aplicativo por sabor
Simplificando pipelines de CI/CD
Apoiar a colaboração da equipe em diferentes builds
Principais recursos
Gera automaticamente arquivos de configuração para Android, iOS e macOS
Suporta nomes de aplicativos e nomes de pacotes personalizados por sabor
Integração com projetos Flutter existentes
Configurável por meio de arquivo YAML
Ícones e telas de inicialização por sabor
Indicado para
Equipes Flutter usando vários sabores de aplicativos
Projetos que exigem compilações específicas do ambiente
Workflows de CI/CD com estágios de implantação distintos
Desenvolvedores que buscam reduzir a configuração manual
Considerações
Requer conhecimento dos conceitos de flavor do Flutter
Pode entrar em conflito com arquivos de configuração editados manualmente
Necessita de configuração YAML adequada para evitar erros
Melhor usado no início do ciclo de vida do projeto
README original
Snapshot do README original do repositório-fonte vinculado. Consulte o repositório para o conteúdo mais recente.
Flutter Flavorizr
A flutter utility to easily create flavors in your flutter application
If you want to support this project, please leave a star, share this project, or consider donating through Github Sponsor.
Getting Started
Let's start by setting up our environment in order to run Flutter Flavorizr
Prerequisites
Side note: this tool works better on a new and clean Flutter project.
Since some processors reference some existing files and a specific base structure, it could be possible that running Flutter Flavorizr over an existing project could throw errors.
Installation
This package is intended to support development of Flutter projects. In general, put it under dev_dependencies, in your pubspec.yaml:
dev_dependencies:flutter_flavorizr:^2.6.0
You can install packages from the command line:
pub get
Create your flavors
Once you have added flutter_flavorizr as a dev dependency, you have to edit your pubspec.yaml and define the flavors.
Example
Create a new file named flavorizr.yaml and define the name of the flavors, in our example apple and banana. For each flavor you have to specify the app name, the applicationId and the bundleId.
Alternatively, add a new key named flavorizr and define a sub item named flavors.
Under the flavors array you can define the name of the flavors, in our example apple and banana. For each flavor you have to specify the app name, the applicationId and the bundleId.
This way of defining flavors will be deprecated in versions 3.x
flavors:apple:app:name:"Apple App"android:applicationId:"com.example.apple"buildConfigFields:field_one:type:"String"value:"example field one"field_two:type:"char"value:"y"field_three:type:"double"value:"20.0"ios:bundleId:"com.example.apple"
variable (for iOS and macOS)
key
type
default
required
description
target
String
false
The type of the target (debug, release, profile). Do not specify a target if you want to apply it to all of them.
The type of the target (debug, release, profile). Do not specify a target if you want to apply it to all of them.
optional
bool
false
false
If true, uses #include? — the build will not fail if the file is missing. Defaults to false (#include).
Global includes (under app.ios or app.macos) are merged with flavor-specific includes. Global entries come first; flavor entries are appended and take precedence for any duplicate keys.
flavorizr:app:ios:includes:-value:"Shared/base.xcconfig"# applied to all targets-value:"Shared/debug.xcconfig"target:debug# applied to debug onlyflavors:apple:app:name:"Apple App"android:applicationId:"com.example.apple"ios:bundleId:"com.example.apple"includes:-value:"Apple/flavor.xcconfig"-value:"Apple/optional.xcconfig"optional:true# → #include? "Apple/optional.xcconfig"-value:"Apple/release.xcconfig"target:release
customConfig (for Android only)
You can define any custom property for android
flavors:apple:app:name:"Apple App"android:applicationId:"com.example.apple"customConfig:versionNameSuffix:"\"-green-prod\""# Don't forget to escape strings with \"signingConfig:flavorSigning.greenversionCode:1000minSdkVersion:23# ..... and any custom property you want to add
This .yml part, generate this custom android flavor:
monochrome (Themed icons on Android >= 13) is optional.
After removing adaptiveIcon key, the adaptive icons generated before will still exist. Please delete adaptiveIcon manually.
Usage
When you finished defining the flavorizr configuration, you can proceed by running the script with:
flutter pub run flutter_flavorizr
You can also run flutter_flavorizr with a custom set of processors by appending the -p (or --processors) param followed by the processor names separated by comma:
flutter pub run flutter_flavorizr -p <processor_1>,<processor_2>
Example
flutter pub run flutter_flavorizr -p assets:download
flutter pub run flutter_flavorizr -p assets:download,assets:extract
Keep in mind that the order of the processors is important. For example, if you want to run the assets:extract processor, you must run it after the assets:download processor.
Also, some processors need assets to be downloaded before running. For example, the android:dummyAssets processor needs the assets:download processor to be run before.
As a rule of thumb, you should always run both assets:download and assets:extract before running any other processor.
If you want to run flutter_flavorizr in verbose mode, you can append the -v (or --verbose) param:
flutter pub run flutter_flavorizr -v
This will print all the logs to the console, including the ones from the processors.
If you want to skip the confirmation step, you can append the -f (or --force) param:
flutter pub run flutter_flavorizr -f
Run your flavors
Once the process has generated the flavors, you can run them by typing
flutter run --flavor <flavorName>
Example
flutter run --flavor apple
flutter run --flavor banana
Currently, due to a bug in the Flutter SDK, it's not possible to run the macOS flavors from the terminal.
You can run them from XCode by selecting the proper schema and by pressing play.
As a temporary workaround, you can apply the following configuration to your flavorizr config:
By default, when you do not specify a custom set of processors by appending the -p (or --processors) param, a default processors set will be used:
assets:download
assets:extract
android:androidManifest
android:flavorizrGradle
android:buildGradle
android:dummyAssets
android:icons
flutter:flavors
flutter:app
flutter:pages
flutter:main
ios:podfile
ios:xcconfig
ios:buildTargets
ios:schema
ios:dummyAssets
ios:icons
ios:plist
ios:launchScreen
macos:podfile
macos:xcconfig
macos:configs
macos:buildTargets
macos:schema
macos:dummyAssets
macos:icons
macos:plist
linux:cmake
linux:runnerCmake
linux:myApplication
windows:mainCppTemplate
windows:runnerRcTemplate
windows:cmake
windows:dummyAssets
windows:icons
google:firebase
huawei:agconnect
assets:clean
ide:config
Customize your app
Flutter_flavorizr creates different dart files in the lib folder. In the flavors.dart file we have the F class which contains all of our customizations.
The process creates a simple title customization: a switch which checks the current appFlavor (defined in our app starting point) and returns the correct value. Here you can write whatever you want, you can create your custom app color palette, differentiate the URL action of a button, and so on.
If you are wondering how to use these getters, you can find an example under the pages folder: in the my_home_page.dart file, the page shown after the launch of the app, we can see a clear reference on the title getter defined in the F class.
Third party services
Google Firebase
In order to flavorize your project and enable Firebase in your flavor you have to define a firebase object below each OS flavor. Under the firebase object you must define the config path of the google-services.json (if you are under Android configuration) or GoogleService-Info.plist (if you are under iOS or macOS configuration).
As you can see in the example below, we added the path accordingly
After running flutter_flavorizr, remember to add the native dependencies for the targeted operative system. You can take advantage of flutterfire_cli to do so. Remember to ignore the generated firebase_options.dart file, as it will conflict with the flavors configuration. Do this instead:
import'package:firebase_core/firebase_core.dart';
import'package:firebase_crashlytics/firebase_crashlytics.dart';
import'package:flutter/foundation.dart';
import'package:flutter/material.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
awaitFirebase.initializeApp(); // Do not pass the options hererunApp(constApp());
}
Huawei AppGallery Connect
In order to flavorize your project and enable AppGallery Connect in your flavor you have to define an agconnect object below each Android flavor. Under the agconnect object you must define the config path of the agconnect-services.json.
As you can see in the example below, we added the path accordingly
Remember to add the native dependencies for the targeted operative system for both Firebase and Huawei AppGallery Connect: flutter_flavorizr will only take care of applying the configuration.
Let the user define its custom set of available instructions.
Questions and bugs
Please feel free to submit new issues if you encounter problems while using this library.
If you need help with the use of the library or you just want to request new features, please use the Discussions section of the repository. Issues opened as questions will be automatically closed.
License
Flutter Flavorizr is available under the MIT license. See the LICENSE file for more info.