Skip to content

Set up multiple environment with React Native (v0.71)

Do Tuan Hung edited this page Mar 7, 2023 · 1 revision

Initialize new React Native app:

npx react-native init ProjectName

Set up multiple environment for project (Android)

  1. Install React Native Config using yarn add react-native-config (if project is using yarn)
  2. Go to build.gradle in android/app and paste this lines:
  • project.ext.envConfigFiles = [ developmentdebug: ".env.development", stagingdebug: ".env.staging", productiondebug: ".env.production", developmentrelease: ".env.development", productionrelease: ".env.production", stagingrelease: ".env.staging" ]
  • Also: apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle"