-
Notifications
You must be signed in to change notification settings - Fork 656
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ENVFILE=.env.xxx has no effect on iOS unless also touching BuildDotenvConfig.rb #698
Comments
This is actually because of the 0ac5511 commit which added Note that a similar regression has been fixed once before in #458. I think the tricky part of solving this is in keeping everyone with all the different setups happy because that commit was due to issue #683 where they are still using |
Adding $ENVFILE in the "input_files" worked for me, and should not trigger a build unless the .env file changed : diff --git a/node_modules/react-native-config/ios/ReactNativeConfig/GeneratedDotEnv.m b/node_modules/react-native-config/ios/ReactNativeConfig/GeneratedDotEnv.m
new file mode 100644
index 0000000..04a2f3d
--- /dev/null
+++ b/node_modules/react-native-config/ios/ReactNativeConfig/GeneratedDotEnv.m
@@ -0,0 +1 @@
+ #define DOT_ENV @{ };
diff --git a/node_modules/react-native-config/react-native-config.podspec b/node_modules/react-native-config/react-native-config.podspec
index 854bfe7..7d17275 100644
--- a/node_modules/react-native-config/react-native-config.podspec
+++ b/node_modules/react-native-config/react-native-config.podspec
@@ -25,7 +25,7 @@ HOST_PATH="$SRCROOT/../.."
"${PODS_TARGET_SRCROOT}/ios/ReactNativeConfig/BuildDotenvConfig.rb" "$HOST_PATH" "${PODS_TARGET_SRCROOT}/ios/ReactNativeConfig"
),
execution_position: :before_compile,
- input_files: ['$PODS_TARGET_SRCROOT/ios/ReactNativeConfig/BuildDotenvConfig.rb'],
+ input_files: ['$PODS_TARGET_SRCROOT/ios/ReactNativeConfig/BuildDotenvConfig.rb', '$ENVFILE'],
output_files: ['$BUILD_DIR/GeneratedInfoPlistDotEnv.h']
}
|
@justin-tay The workaround with touching the |
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:
|
Thank you very much bro @quiringk I also had the same problem you had... I changed schemas but kept taking another .env that was not the one that corresponded... and with your solution with those two more lines of code, it worked for me too! |
Totatly worked for me man, thanks! Thats what my code looks like now:
|
It work |
@LeQuy-123
|
I put this in my "clean" package.json command:
And it works for IOS - what about Android? |
Its work's on android too
…On Sat, 10 Jun, 2023, 9:39 pm William Bell, ***@***.***> wrote:
I out this in my "clean" package.json command:
rm -f node_modules/react-native-config/ios/ReactNativeConfig/GeneratedDotEnv.m
And it works for IOS - what about Android?
—
Reply to this email directly, view it on GitHub
<#698 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/A7UOOBKCAUZMAWIK76QTKZ3XKSL3JANCNFSM6AAAAAAR4E42NY>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Overall, this was indeed the temporary workaround! But, I'm just sharing a cleaner code, since a part here is redundant, and quotes in the original answer used which will cause a failure. This script should work for everyone:
|
It is a temporary fix for env variable. But it needs to run every time. Which is not good. |
Worked with adding the schema name within single quotes. |
This is pretty complicated, why not the basic overwrite .env then? Something like this?
Would be great if there is a stable fix possible; but the cp is workable |
this is working fine but it is not a good solution. cause of need to delete every time. Without deleting .env not updating in ios. Please resolve. |
Please fix this issue (.env not updating without deleting GeneratedDotEnv.m) and Update it in to latest version. |
For me, the issue started happening after I wanted to change something and I followed the tutorial from: https://www.youtube.com/watch?v=rhdOWYqc-Cg&t=1551s&ab_channel=JASACADAMY
Solution, as someone mentioned above
|
how did you get below to work?
My folder structure I get an error i ended up downgrading to 0.4.5 and did none of the above. it works. |
@jliukai having the same issue. Seems like PROJECT_DIR is empty in pre-build script. |
I ended up using this script in pre-build phases for each scheme:
In some reason $PROJECT_DIR is empty in pre-build action, but $WORKSPACE_PATH worked well for me. |
Using react-native-config from the command line with the ENVFILE=.env.xxx syntax doesn't change the config available in the app. The workaround listed in #692 fixes the problem, though that issue suggests the workaround hasn't always been required.
Haven't done any setup in Xcode with schemes or anything. Just trying it out via the command line. From looking at the documentation this should work, so raising an issue.
Example commands used (Mac shell):
ENVFILE=.env.xxx npx react-native run-ios
(wrong config in app)
touch node_modules/react-native-config/ios/ReactNativeConfig/BuildDotenvConfig.rb
ENVFILE=.env.xxx npx react-native run-ios
(correct config in app)
Notable versions in the environment are:
react-native 0.69.5
react-native-config 1.4.11
Happy to provide any other details if useful.
The text was updated successfully, but these errors were encountered: