Open PatNeedham opened 7 years ago
The suggestion to add echo "${ENVFILE}" > /tmp/envfile
as a run script in the build scheme seems to have worked great... however, it only seems to be working for me if I build/run from the command line. If I try to run a build inside Xcode, the ENVFILE
var is not defined and thus errors and stops the build process.
Any suggestion on how to fix this? Or how to run builds for production and/or to my physical device?
@PatNeedham and @andersryanc
Did you get this working?
I've got it working now by adding this in XCODE in:
Edit scheme > Build > Pre-actions
New Run Script Action
Type a script or drag a script file
I added:if [ "${ENVFILE}" ]; then echo "${ENVFILE}" > /tmp/envfile ; else echo ".env" > /tmp/envfile; fi
Now I can also use
# with an ENVFILE
ENVFILE=.env.prod react-native run-ios
# without, just the default
react-native run-ios
the same as on Android
I ended up not needing this package.
@andersryanc
Did you use something else then?
No, I just realized I didn't need a config package in general. I think I may have even removed another dependency I was trying to use this with.
I am trying to determine why the react-native-config module is working fine on the Android side of my app (retrieving correct env variables from either .env.dev. or .env.prod) but failing to do so when running on iOS. When logging to the console, all values of
Config.VARIABLE_NAME
show up as undefined.I thought starting from the official example and comparing to see what I'm doing wrong would be a good start. but the iOS instructions from the root directory readme do not match up with the
Example/ios/Example.xcodeproj
project file when verifying the Running on iOS section:That was not the case for me, as when I opened
Example/ios/Example.xcodeproj
after cloning the repo, the "Example (prod)" scheme was nowhere to be found. Additionally, runningENVFILE=.env.prod react-native run-ios
andreact-native run-ios
both resulted in the app running withAPI_URL=localhost
as the center text even though in.env.prod
it's defined ashttps://myapi.com
.However, when I edited the
Example
scheme within Xcode to addecho ".env.prod" > /tmp/envfile
as a Pre-action run script,https://myapi.com
DID appear on the app, regardless of whether I preceededrun-ios
withENVFILE=.env.prod
orENVFILE=.env
.That leads me to ask this: is the extra
ENVFILE=
_envfile only meant to be used withreact-native run-android
and not with the iOS equivalent? That led me to wonder ifecho ".env.prod" > /tmp/envfile
could somehow be changed toecho "${ENVFILE}" > /tmp/envfile
. And it worked! RunningENVFILE=.env react-native run-ios
andENVFILE=.env.prod react-native run-ios
now give the expected results, with env variables being retrieved from the specified file.Hopefully this issue and my workaround can help others who are having trouble getting
react-native-config
to work properly on iOS.