React-native-config: [iOS] Automatic envfile selection without the need for multiple schemes

Created on 23 Dec 2018  路  2Comments  路  Source: luggit/react-native-config

I noticed that the README stats the iOS process, using multiple build schemes, is experimental. I agree and I don't think its optimal for the common case. One of the major problems with using pre-build scripts is that the build environment hasn't been set up yet, so you can't inspect things such as the build configuration.

I opted instead to use a Run Script as part of the actual build process, and that is serving me really nicely. For Debug builds, it automatically chooses .env.development, and for Release builds, .env.production.

I'll leave it up to the maintainers to decide if this is the right approach to include in the README. I just wanted to offer up my quick script (which is adapted from RN's boilerplate ios build script node_modules/react-native/scripts/react-native-xcode.sh) to be helpful.

image

case "$CONFIGURATION" in
  *Debug*)
    echo ".env.development" > /tmp/envfile
    ;;
  "")
    echo "$0 must be invoked by Xcode"
    exit 1
    ;;
  *)
    echo ".env.production" > /tmp/envfile
    ;;
esac

echo "Using envfile $(cat /tmp/envfile)"

Hope this helps someone simplify their workflow!

Most helpful comment

I'm not sure if this is the right way for all projects... particularly mine, where we have 3 different environments, not just development and production.

We only have on scheme, and we use fastlane to package up our application, so we opted to create a lane that does the dirty work:

$ fastlane ios development env:(development|production|staging)

Which looks like this:

lane development do |options|
  ENV["ENVFILE"] = options[:env]
  // ... Continue as usual, match, gym, whatever
end

Though it does suck when using Xcode to use cached build data and whatever, cause then we have to explicitly go:

$ echo ".env.{flavor}" > /tmp/envfile

Then switch to Xcode and click run.

I'm wondering if there's a way to do all of this WITHOUT depending on Xcode doing the configuration... our goal is for all tasks to be devops/CI tasks runnable without having to explicitly set up Xcode steps and build actions.

All 2 comments

I'm not sure if this is the right way for all projects... particularly mine, where we have 3 different environments, not just development and production.

We only have on scheme, and we use fastlane to package up our application, so we opted to create a lane that does the dirty work:

$ fastlane ios development env:(development|production|staging)

Which looks like this:

lane development do |options|
  ENV["ENVFILE"] = options[:env]
  // ... Continue as usual, match, gym, whatever
end

Though it does suck when using Xcode to use cached build data and whatever, cause then we have to explicitly go:

$ echo ".env.{flavor}" > /tmp/envfile

Then switch to Xcode and click run.

I'm wondering if there's a way to do all of this WITHOUT depending on Xcode doing the configuration... our goal is for all tasks to be devops/CI tasks runnable without having to explicitly set up Xcode steps and build actions.

Much appreciated @joshjordan solution!

Was this page helpful?
0 / 5 - 0 ratings