Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Switching iOS Schemes not working #692

Closed
theobouwman opened this issue Oct 20, 2022 · 10 comments
Closed

Switching iOS Schemes not working #692

theobouwman opened this issue Oct 20, 2022 · 10 comments

Comments

@theobouwman
Copy link

I followed: https://www.bigbinary.com/books/learn-react-native/handling-environment-specific-configurations-in-react-native

But when I switch from Staging scheme to Production scheme the .env is changes to the correct values. But when I log the variables they don't change. I tried removing the app and running metro with reset-cache but noting changes.

What can I do?

@theobouwman
Copy link
Author

After I clean the build folder it works, what is that?

@justin-tay
Copy link

I seem to remember that this used to work.

The generated file in node_modules/react-native-config/ios/ReactNativeConfig/GeneratedDotEnv.m doesn't seem to get rebuilt automatically when the scheme gets changed. Cleaning will trigger a full rebuild so that works.

As a workaround in your Build Pre-actions script touching node_modules/react-native-config/ios/ReactNativeConfig/BuildDotenvConfig.rb seems to get the GeneratedDotEnv.m rebuilt properly.

As an example the script will now look similar to the one below
cp "${PROJECT_DIR}/../.env.staging" "${PROJECT_DIR}/../.env"
touch "${PROJECT_DIR}/../node_modules/react-native-config/ios/ReactNativeConfig/BuildDotenvConfig.rb"

@FrankyCTY
Copy link

FrankyCTY commented Oct 23, 2022

@justin-tay It works for me, thanks :)
I did not copy to overwrite the .env, instead I do this:

echo ".env.production" > /tmp/envfile
touch "${PROJECT_DIR}/../node_modules/react-native-config/ios/ReactNativeConfig/BuildDotenvConfig.rb"

@theobouwman
Copy link
Author

@justin-tay thanks. It works!

@FadiAboMsalam
Copy link

@justin-tay your solution also works thankss 🎉

@quiringk
Copy link

Just wanted to chime in here. I went through tutorials (https://www.youtube.com/watch?v=rhdOWYqc-Cg&t=1551s&ab_channel=JASACADAMY) and set up schemes + targets for my different envs. I was running into the issue where the .env would get overwritten successfully by the correct .env.[environment] file but the actual variables in the code weren't changing (when you used them). Occasionally they would change after multiple clear builds, etc but even then there was no consistency and most of the time that didn't work. Eventually I added everything I could find in the issues here + deleting the builds on the simulator so that they had to be reinstalled and all the sudden switching back and forth between schemes started working and changing the variables every time. So here is what my pre-actions script looks like for each environment:

cp "${PROJECT_DIR}/../.env.dev" "${PROJECT_DIR}/../.env"

echo “.env.dev” > /tmp/envfile

touch "${PROJECT_DIR}/../node_modules/react-native-config/ios/ReactNativeConfig/BuildDotenvConfig.rb"

@nppull
Copy link

nppull commented Feb 23, 2023

Just wanted to chime in here. I went through tutorials (https://www.youtube.com/watch?v=rhdOWYqc-Cg&t=1551s&ab_channel=JASACADAMY) and set up schemes + targets for my different envs. I was running into the issue where the .env would get overwritten successfully by the correct .env.[environment] file but the actual variables in the code weren't changing (when you used them). Occasionally they would change after multiple clear builds, etc but even then there was no consistency and most of the time that didn't work. Eventually I added everything I could find in the issues here + deleting the builds on the simulator so that they had to be reinstalled and all the sudden switching back and forth between schemes started working and changing the variables every time. So here is what my pre-actions script looks like for each environment:

cp "${PROJECT_DIR}/../.env.dev" "${PROJECT_DIR}/../.env"

echo “.env.dev” > /tmp/envfile

touch "${PROJECT_DIR}/../node_modules/react-native-config/ios/ReactNativeConfig/BuildDotenvConfig.rb"

I'm having the same problem, can you share the podfile?

@nppull
Copy link

nppull commented Feb 23, 2023

I get error with version 1.5.0
Downgrading to 1.4.6 fixes for me

@Brawl345
Copy link

As a workaround in your Build Pre-actinos script touching node_modules/react-native-config/ios/ReactNativeConfig/BuildDotenvConfig.rb seems to get the GeneratedDotEnv.m rebuilt properly.

As an example the script will now look similar to the one below cp "${PROJECT_DIR}/../.env.staging" "${PROJECT_DIR}/../.env" touch "${PROJECT_DIR}/../node_modules/react-native-config/ios/ReactNativeConfig/BuildDotenvConfig.rb"

THANK YOU!!! Wasted a lot of time trying to get this library to work, this was the ONLY thing that worked. No cleaning, reset-cache or any other magic necessary!

@JohnBonesOrtega
Copy link

Just wanted to chime in here. I went through tutorials (https://www.youtube.com/watch?v=rhdOWYqc-Cg&t=1551s&ab_channel=JASACADAMY) and set up schemes + targets for my different envs. I was running into the issue where the .env would get overwritten successfully by the correct .env.[environment] file but the actual variables in the code weren't changing (when you used them). Occasionally they would change after multiple clear builds, etc but even then there was no consistency and most of the time that didn't work. Eventually I added everything I could find in the issues here + deleting the builds on the simulator so that they had to be reinstalled and all the sudden switching back and forth between schemes started working and changing the variables every time. So here is what my pre-actions script looks like for each environment:

cp "${PROJECT_DIR}/../.env.dev" "${PROJECT_DIR}/../.env"

echo “.env.dev” > /tmp/envfile

touch "${PROJECT_DIR}/../node_modules/react-native-config/ios/ReactNativeConfig/BuildDotenvConfig.rb"

this worked for me. I am also working with multiple targets. thank you.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants