Config product flavor
  • 🥳Config Build Flavor on IOS
  • 😍Config Build Flavor on Flutter
Powered by GitBook
On this page

Config Build Flavor on IOS

Create a build flavor with the name: Nightly

NextConfig Build Flavor on Flutter

Last updated 2 years ago

  1. Click on the Runner, click the + button, choose duplicate "Debug Configuration", and change the name to "Debug-Nightly".

  1. Create New Scheme, named "Nightly" with "target Runner". After that edit scheme with "Build Configuration" in "run, test, analyze" to "Debug-Nightly".

  2. Change "Product bundle identifier" and "Product name" for every flavor.

  1. With another variable like the "Google map API" key. Define a variable in user-defined, and change the value for each flavor

Add a file for each environment

an example is add GoogleService-Info.plist

  1. Copy to project file like this:

  1. Select target Runner, and tab Build Phases, click + button, edit the name of the script to what you want.

  1. This script means copying the file to the right path when we build with a flavor.

the # Type a script or drag a script file from your workspace to insert its path.

environment="Nightly"

# Regex to extract the scheme name from the Build Configuration
# We have named our Build Configurations as  etc.
# Here, Nightly and Staging, Production are the scheme names. This kind of naming is required by Flutter for flavors to work.
# We are using the $CONFIGURATION variable available in the XCode build environment to extract 
# the environment (or flavor)
# For eg.
# If CONFIGURATION="Debug-Nightly", then environment will get set to "".
if [[ $CONFIGURATION =~ -([^-]*)$ ]]; then
  environment=${BASH_REMATCH[1]}
fi

echo $environment

# Name and path of the resource we're copying
GOOGLESERVICE_INFO_PLIST=GoogleService-Info.plist
GOOGLESERVICE_INFO_FILE=${PROJECT_DIR}/config/${environment}/${GOOGLESERVICE_INFO_PLIST}

# Make sure GoogleService-Info.plist exists
echo "Looking for ${GOOGLESERVICE_INFO_PLIST} in ${GOOGLESERVICE_INFO_FILE}"
if [ ! -f $GOOGLESERVICE_INFO_FILE ]
then
  echo "No GoogleService-Info.plist found. Please ensure it's in the proper directory."
  exit 1
fi

# Get a reference to the destination location for the GoogleService-Info.plist
# This is the default location where Firebase init code expects to find GoogleServices-Info.plist file
PLIST_DESTINATION=${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app
echo "Will copy ${GOOGLESERVICE_INFO_PLIST} to final destination: ${PLIST_DESTINATION}"

# Copy over the prod GoogleService-Info.plist for Release builds
cp "${GOOGLESERVICE_INFO_FILE}" "${PLIST_DESTINATION}"

Change FLUTTER_TARGET in User-Defined for each environment.

staging: lib/main_stg.dart nightly: lib/main_nightly.dart production: lib/main_production.dart

That's all you need to do.

🥳