I have an iOS for which I want to run a build phase that reads a value from a JSON file, export that as an environment variable and then read that in my Info.plist.
I currently have:
# Build Scripts/SetAPIVersion
set -e
if ! which jq > /dev/null; then
echo "error: jq is missing. Be sure to git pull `dev-box` and run apply.sh"
exit 1
fi
export API_VERSION =$(cat ../src/version.json | jq .api)
echo "Set API Version to $(API_VERSION)!"
My application will build however the value does not appear to be set. What am I doing wrong here?
The shell interpreter is run as a subprocess. When it
export
s an environment variable, that only affects that shell interpreter process and its subprocesses, but doesn't affect the parent process (i.e. Xcode) nor its sibling processes (other build phases).You can make the shell script build phase take an input file, say Info.plist.in, and produce Info.plist from that. It would transform the input to the output however you like. For example, it could use
sed
to replace a special string with the value it should have. Be sure to configure the inputs and outputs of the run-script build phase as appropriate.Alternatively, you could have the run-script build phase produce a header file that defines a macro, say api_version.h which
#define
sAPI_VERSION
,#include
that header file in your Info.plist, and enable preprocessing of Info.plist in the build settings. Again, make sure the inputs and outputs of the run-script phase are correct.