Skip to content
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

Cannot read env variable in info.plist #437

Open
MRSEREY opened this issue Mar 27, 2020 · 10 comments
Open

Cannot read env variable in info.plist #437

MRSEREY opened this issue Mar 27, 2020 · 10 comments

Comments

@MRSEREY
Copy link

MRSEREY commented Mar 27, 2020

I have follow the doc until:
Availability in Build settings and Info.plist
step 6. create new build phase for the scheme which will generate "tmp.xcconfig" before each build exposing values to Build Settings and Info.plist (this snippet has to be placed after "echo ... > tmp/envfile" if approach explained below is used)

  • I have created schema for my app then in build -> pre-actions. I click add new script and paste the following:
    echo ".env.staging" > /tmp/envfile
    "${SRCROOT}/../node_modules/react-native-config/ios/ReactNativeConfig/BuildXCConfig.rb" "${SRCROOT}/.." "${SRCROOT}/tmp.xcconfig"
  • then I go to info.plist and use $(MYENVVAR) to get value from .env file but it could not get any value.

Has anyone ever faced it?

Happy to see any comments

@techgerm
Copy link

@MRSEREY this comment helped me.

Also, be sure to clean your build before running and testing it.

@MRSEREY
Copy link
Author

MRSEREY commented Apr 2, 2020

@germanp173 thanks, but It still does not work.
in build settings -> packaging I change

  • Info.plist Other Preprocessor Flags to -traditional
  • Info.plist Preprocessor Prefix File to build/GeneratedInfoPlistDotEnv.h
  • Preprocess Info.plist File to yes
  • remove postinstall script specific for react-native-config in Podfile
  • pod install
  • clean profile and build

I got an error build/GeneratedInfoPlistDotEnv.h not found

@techgerm
Copy link

techgerm commented Apr 2, 2020

@MRSEREY sorry I should have been more clear and specified that the comment helped me by instructing me to remove those old settings which you just laid out (make sure you read the comment carefully). After I removed those Preprocessor flags and cleaned the project, it worked for me.

If you didn't have any of those old settings in place then:

  1. When you open ${SRCROOT}/tmp.xcconfig after your build, do you see your environment variables there?

@MRSEREY
Copy link
Author

MRSEREY commented Apr 8, 2020

@germanp173 it didn't see even tmp.xcconfig in ios folder

@MRSEREY
Copy link
Author

MRSEREY commented Apr 8, 2020

@germanp173 I can see tmp.xcconfig file now which contain my env there. But I still cannot access it in Info.plist.
I use this to access env $(MY_VAR)

@ducpt2
Copy link

ducpt2 commented Apr 27, 2020

hi @MRSEREY , do you resolve this issue? Thanks

@maxkomarychev
Copy link
Contributor

maxkomarychev commented Apr 27, 2020

@MRSEREY have you enabled "Provide build settings from " ?

@davincho
Copy link

I ran into the same issue and fixed it by referencing the correct env variable name.

It used to be: __RN_CONFIG_XXX
Correct one: RNC_XXX

For more details, have a look at the generating script:

New way: https://github.com/luggit/react-native-config/blob/master/ios/ReactNativeConfig/BuildDotenvConfig.rb#L29
Old way: https://github.com/luggit/react-native-config/blob/v0.11.7/ios/ReactNativeConfig/BuildDotenvConfig.ruby#L69

@abdeali41
Copy link

I ran into the same issue and fixed it by referencing the correct env variable name.

It used to be: __RN_CONFIG_XXX
Correct one: RNC_XXX

For more details, have a look at the generating script:

New way: https://github.com/luggit/react-native-config/blob/master/ios/ReactNativeConfig/BuildDotenvConfig.rb#L29
Old way: https://github.com/luggit/react-native-config/blob/v0.11.7/ios/ReactNativeConfig/BuildDotenvConfig.ruby#L69
I was having the same issue. This worked for me Thanks!

@aryella-lacerda
Copy link

For me, there were two problems:

  1. If you have syntax errors in your .env file, the process fails without throwing any env-file-specific errors. In my case, I removed all comments and empty lines, and switched all double-quotes for single-quotes. Not sure which of these was the syntax error, but that fixed it.

  2. Forgot to add Config.xcconfig to target membership.

Worked perfectly after that 👍

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

No branches or pull requests

7 participants