The value that is passed to --variant
option is basically a combination of product flavor and build type. By default there are 2 build types defined - debug
and release
. To add flavors like development
, staging
, production
, define them below buildTypes
in android/app/build.gradle
-
buildTypes {
.....
}
flavorDimensions "default"
productFlavors {
production {}
staging {}
development {}
}
Now with a configuration like this -
project.ext.envConfigFiles = [
developmentdebug: ".env.development",
developmentrelease: ".env.development",
stagingdebug: ".env.staging",
stagingrelease: ".env.staging",
productiondebug: ".env.production",
productionrelease: ".env.production",
]
apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle"
you can now build like you wanted -
npx react-native run-android --variant=stagingdebug
npx react-native run-android --variant=productionrelease
You can read more about Android build types and flavors here.
https://developer.android.com/studio/build/build-variants
For a similar configuration in iOS, follow this excellent tutorial.
https://www.bigbinary.com/books/learn-react-native/handling-environment-specific-configurations-in-react-native