Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A shell script to selectively copy your GoogleService-Info.plist into your app bundle based on the current build configuration.
# Name of the resource we're selectively copying
GOOGLESERVICE_INFO_PLIST=GoogleService-Info.plist
# Get references to dev and prod versions of the GoogleService-Info.plist
# NOTE: These should only live on the file system and should NOT be part of the target (since we'll be adding them to the target manually)
GOOGLESERVICE_INFO_DEV=${PROJECT_DIR}/${TARGET_NAME}/Firebase/Dev/${GOOGLESERVICE_INFO_PLIST}
GOOGLESERVICE_INFO_PROD=${PROJECT_DIR}/${TARGET_NAME}/Firebase/Prod/${GOOGLESERVICE_INFO_PLIST}
# Make sure the dev version of GoogleService-Info.plist exists
echo "Looking for ${GOOGLESERVICE_INFO_PLIST} in ${GOOGLESERVICE_INFO_DEV}"
if [ ! -f $GOOGLESERVICE_INFO_DEV ]
then
echo "No Development GoogleService-Info.plist found. Please ensure it's in the proper directory."
exit 1
fi
# Make sure the prod version of GoogleService-Info.plist exists
echo "Looking for ${GOOGLESERVICE_INFO_PLIST} in ${GOOGLESERVICE_INFO_PROD}"
if [ ! -f $GOOGLESERVICE_INFO_PROD ]
then
echo "No Production 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
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
if [ "${CONFIGURATION}" == "Release" ]
then
echo "Using ${GOOGLESERVICE_INFO_PROD}"
cp "${GOOGLESERVICE_INFO_PROD}" "${PLIST_DESTINATION}"
else
echo "Using ${GOOGLESERVICE_INFO_DEV}"
cp "${GOOGLESERVICE_INFO_DEV}" "${PLIST_DESTINATION}"
fi
@tylermilner

This comment has been minimized.

Copy link
Owner Author

@tylermilner tylermilner commented Nov 16, 2017

Updated the final step in the script (copying the appropriate GoogleService-Info.plist) to support paths with spaces. Thanks to @t0rn for pointing out the issue and providing a fix with his fork.

@reneeOlson

This comment has been minimized.

Copy link

@reneeOlson reneeOlson commented Aug 16, 2018

Hi Tyler. I really appreciate your solution because I did not want to add another target. However, I’ve had a couple things occur since I implemented it yesterday. The first thing was that xcode asked me to add a new URL scheme for the production version, which I did and things seemed to ran ok yesterday. But today, I keep getting a message — No default storage bucket found - on the debug version. I’ve had this app/firebase debug project working fine regarding storage until today. I’ve never used a shell script before, so not sure if it’s the reason for this error. What are your thoughts? Appreciate your help! FYI - I also posted this on the Medium website before here.

@reneeOlson

This comment has been minimized.

Copy link

@reneeOlson reneeOlson commented Aug 20, 2018

Hi Tyler. I ended up figuring it out, so never mind. Thanks again for your script and tutorial on Medium.

@NoaD

This comment has been minimized.

Copy link

@NoaD NoaD commented Jan 18, 2021

This script and the article in Medium are great.
I had to change the script to handle mac app as well - the target location is different, so I added the following

if [ "${SWIFT_PLATFORM_TARGET_PREFIX}" == "macos" ]
then
    PLIST_DESTINATION=${BUILT_PRODUCTS_DIR}/${CONTENTS_FOLDER_PATH}/Resources
else
    PLIST_DESTINATION=${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app
fi
@saleemabbas51214

This comment has been minimized.

Copy link

@saleemabbas51214 saleemabbas51214 commented Mar 3, 2021

Hi I am having an issue when i integrated this script and used the approach you suggested into my existing project . The issue is as follows
error: Could not get GOOGLE_APP_ID in Google Services file from build environment

@budidino

This comment has been minimized.

Copy link

@budidino budidino commented Jul 9, 2021

When targeting watchos use:
PLIST_DESTINATION=${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.appex

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment