React-native-config: How to access variables in project.pbxproj ?

Created on 6 Aug 2017  路  4Comments  路  Source: luggit/react-native-config

I want to add Crashlytics to my project.
One of the steps is "Add a Run Script Build Phase". I should add line:
"${PODS_ROOT}/Fabric/run" <FABRIC_API_KEY> <BUILD_SECRET>
So, FABRIC_API_KEY and BUILD_SECRET I'd like to configure via .env-file (to set up different Crashlytics-accounts for different environments).

In project.pbxproj it looks like:
BCC7406A1F35F118000AEAAA /* ShellScript */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputPaths = ( ); outputPaths = ( ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; shellScript = "\"${PODS_ROOT}/Fabric/run\" <FABRIC_API_KEY> <BUILD_SECRET>"; };

@GantMan , I'm not very familiar with XCode, because it's my first RN-project.

Also I should add to Info.plist file. According to react-native-config documentation, I have access to variables from my .env-file in Info.plist. Am I right?

Most helpful comment

@NachtRitter I achieved similar thing using this over-complicated method, but didn't find anything easier, because BuildDotenvConfig.ruby just deletes /tmp/envfile after it's processed.

  1. use export in .env.* files so you can use the values as environment variables in your build script:
export ABC=1
  1. backup env file name in scheme pre-action script (reading $ENVFILE in the build script didn't work for me for some reason)
if [ -n /tmp/envfile ]
then
  cp -f /tmp/envfile /tmp/my_envfile
else
  echo ".env" > /tmp/my_envfile
fi
  1. run the envfile in build script to get your variables set as environment variables so as you can use them in the script
envfile=$(< /tmp/my_envfile)
source $PROJECT_DIR/../$envfile
echo $ABC

All 4 comments

@pedro do you have any solutions for my case?

@NachtRitter I achieved similar thing using this over-complicated method, but didn't find anything easier, because BuildDotenvConfig.ruby just deletes /tmp/envfile after it's processed.

  1. use export in .env.* files so you can use the values as environment variables in your build script:
export ABC=1
  1. backup env file name in scheme pre-action script (reading $ENVFILE in the build script didn't work for me for some reason)
if [ -n /tmp/envfile ]
then
  cp -f /tmp/envfile /tmp/my_envfile
else
  echo ".env" > /tmp/my_envfile
fi
  1. run the envfile in build script to get your variables set as environment variables so as you can use them in the script
envfile=$(< /tmp/my_envfile)
source $PROJECT_DIR/../$envfile
echo $ABC

hi @NachtRitter , my pr #349 allows reading values from env file in Build settings. please give it a try, thanks

@maxkomarychev Thanks, however I'm not working currently with React Native projects. So maybe someone else will check it

Was this page helpful?
0 / 5 - 0 ratings