lugg / react-native-config

Bring some 12 factor love to your mobile apps!
MIT License
4.83k stars 656 forks source link

How to access variables in project.pbxproj ? #142

Open NachtRitter opened 7 years ago

NachtRitter commented 7 years ago

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?

NachtRitter commented 7 years ago

@pedro do you have any solutions for my case?

Buthrakaur commented 7 years ago

@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
  2. 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
  3. 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
maxkomarychev commented 5 years ago

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

NachtRitter commented 5 years ago

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