I have configured ENVs using react-native-config package. I have 3 different ENVs which I have defined in app/build.gradle
This is defined as below -
project.ext.envConfigFiles = [
debug: ".env.dev",
stagingRelease: ".env.staging",
prodRelease: ".env.prod",
]
Now when I run npx react-native run-android --variant=prodRelease. It is breaking with error - Task 'installProdRelease' not found in project ':app'.
How can I make it working so that I can run different environments in app ?
The value that is passed to
--variantoption is basically a combination of product flavor and build type. By default there are 2 build types defined -debugandrelease. To add flavors likedevelopment,staging,production, define them belowbuildTypesinandroid/app/build.gradle-Now with a configuration like this -
you can now build like you wanted -
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