In Flutter, you should select build flavors instead of build variants (combination of build flavor and build type). Flutter run
has a --flavor
option, but not buildType
.
Specify build flavors:
In build.gradle
below defaultConfig {}
:
android {
...
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
debug {
applicationIdSuffix ".debug" // Optional, you don't need to create a separate applicationId for debug.
signingConfig signingConfigs.debug
}
}
flavorDimensions "default"
productFlavors {
dev {
applicationIdSuffix ".dev"
}
qa {
applicationIdSuffix ".qa"
}
prod {
}
}
}
Run your Flutter app with specific build flavor:
- On the command line: use
flutter run --flavor flavorName
, or
- In Android Studio: Run/debug configuration Drop Down → Edit Configuration... →
Additional run args:
→ Add --flavor dev
or --flavor qa
or --flavor prod
Confirm the applicationId has changed. I use package_info_plus for this:
- Add
package_info_plus: ^1.0.4
to pubspec.yaml
- Add the code somewhere:
PackageInfo.fromPlatform().then((PackageInfo packageInfo) {
print("Package name: ${packageInfo.packageName}");
});
- The packageName will have both the build flavor and build type. In my case, because of
applicationIdSuffix
in both buildTypes
and productFlavors
, com.example.dev.debug
. You could remove applicationIdSuffix ".debug"
if you don't need/ want it.
Now we can have separate build flavor directories with their own google-services.json
.