[SOLVED] How to set the custom env file when archiving the build with Xcode react-native-dotenv


This Content is from Stack Overflow. Question asked by Vimukthi Jayasinghe

I have followed multiple env files in the app.

  • .env.development
  • .env.production
  • .env-staging

I am using react-native-dotenv (https://www.npmjs.com/package/react-native-dotenv) package to do that.

I have set three different values for the API_BASE_URL since I need to connect to the backend according to the environment.
currently working with debug mode by setting environment like this => APP_ENV=staging react-native start

My question is when I release a build using Xcode archive, how to set the .env.staging file values? it is always picking the .env.production values. I need to get a build that app connected to the staging backend URL


You need archive by option targets (in Xcode).
Firstly you should create targets for your environment (duplicate main target and rename). After that you can choice which environment to build.

This Question was asked in StackOverflow by Vimukthi Jayasinghe and Answered by Gennady Sabirovsky It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?