react native config cannot read env file in ios

10.8k Views Asked by At

I have follow the doc: https://github.com/luggit/react-native-config#ios 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? my package json lock is "react-native-config": "0.11.7"

Happy to see any comments

1

There are 1 best solutions below

0
On

If you can see empty config file in your JS when importing import Config from 'react-native-config' and if you are using Pods just add (without react-native link react-native-config)

pod 'react-native-config', :path => '../node_modules/react-native-config/react-native-config.podspec'

in your Podfile.

And try to update module version

"react-native-config": "^1.0.0"