DEV Community

Cover image for react-native rnfirebase Firebase GoogleService-Info.plist with different build schemes, environment
Tùng Cao
Tùng Cao

Posted on

10 1

react-native rnfirebase Firebase GoogleService-Info.plist with different build schemes, environment

When you integration your react-native app with firebase (rnfirebase). You using Xcode schemes for develop, production. This post will introduce you how Firebase google plist work with different build schemes.

Step 1: Copy plist file to app directory. Look like:
ios

  • AppName (your app name) -- Firebase --- Dev ---- GoogleService-Info.plist --- Prod ---- GoogleService-Info.plist

Alt Text

Step 2: Open XCode, create new Groups with name "Firebase" and "Dev", "Prod" inside.
Alt Text

Step 3: Right click Dev and Prod, click "add files to ..".

  • Uncheck "Copy items if needed"
  • Uncheck "Add to target"

Alt Text
Alt Text

Step 4: In the Xcode project navigator, select the app target. Switch to the Build Phases tab at the top, then add a New Run Script Phase. Name the phase “Setup Firebase Environment GoogleService-Info.plist”
And place it before the “Copy Bundle Resources” step.
Alt Text

Step 5: Implement a shell script that will copy the appropriate GoogleService-Info.plist into the app bundle based on the build configuration. Copy and paste the following shell script into the run script phase you just created:



# 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


Enter fullscreen mode Exit fullscreen mode

It done!

Top comments (5)

Collapse
 
anhdo9797 profile image
Đỗ Công Phước Anh

Hi, thank you for your Post. I applied but get Error: "Could not get GOOGLE_APP_ID in Google Services file from build environment"
When I add GoogleServices-Info.plist in root iOS
Image description

I get error

Command PhaseScriptExecution failed with a nonzero exit code

can you help me?

Collapse
 
noumanstackone profile image
noumanjaved

How do I verify that the right file is actually picked

Collapse
 
stef0211 profile image
Stefan

I want to know the same. Did you find answer yet?

Collapse
 
noumanstackone profile image
noumanjaved

Yes, you can check all the "echo" logs from the scripts by navigating to
View > Navigators > Reports and then select Build menu from the left bar.

Collapse
 
luizrebelatto profile image
Luiz Gabriel

Great Article! Help me to implement notification push in my application

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay