76

For setting up firebase i am using two config 1.GoogleService-Info-test.plist, 2.GoogleService-Info-prdn.plist for UAT and Production. For installing crashlytics using firebase i have followed firebase documentation https://firebase.google.com/docs/crashlytics/get-started?authuser=1#ios. But when i try to run, it throws error in build phase while running script.

I tried without changing config file name and it worked.

Error msg at build phase while running fabric run script "Could not get GOOGLE_APP_ID in Google Services file from build environment".

Can anyone suggest better solution to achieve my requirement.

Mukesh Gami
  • 1,070
  • 1
  • 9
  • 15

25 Answers25

40

This is one way you can do it, by having your projects environments separated by targets, by doing so you can then add your different plist files and just check the target that they belong to, that way when you compile the target it will take it's corresponding plist file

Sample Image

Another way to do it, or to look up how to do it, it's called multiple environments with firebase, here are some helpful links

Use different GoogleService-Info.plist for different build schemes

https://medium.com/rocket-fuel/using-multiple-firebase-environments-in-ios-12b204cfa6c0

Samuel Chavez
  • 768
  • 9
  • 12
  • 7
    This is brilliant. This should be part of the FB documentation. – barrylachapelle Sep 02 '19 at 20:24
  • 4
    Don't create targets, use "build configurations" for this purpose. – DanSkeel Nov 08 '20 at 16:26
  • @DanSkeel why? That sounds like the wrong tool for this task – Ky - Nov 19 '20 at 16:28
  • 7
    @BenLeggiero because targets are designed for completely different apps (e.g. watch app), and not for configurations of same app. Thats why they have `build configurations` for this purpose. Main downside of this approach - in `pbxproj` file for each source file you get duplicate lines that increase the complexity of resolving conflicts. You can add user defined build setting with a name of the config file and use it in code to get proper file depending on build configuration. – DanSkeel Nov 19 '20 at 19:02
  • 1
    Great reasoning! Thanks, @DanSkeel – Ky - Nov 20 '20 at 16:43
35

This worked for me:

When install Crashlytic with Firebase, for multiple scheme, you can have error Could not get GOOGLE_APP_ID in Google Services file from build environment. You can fix it by:

  • In Build Settings, add a user define for file name in User Defined:

Add file name for each scheme in User Defined

  • In Build Phases, tap plus button, New Run Script Phase above your Crashlytic build phase, and type this code to the text field. Remember to rename %YOUR_CUSTOM_PATH_TO_FOLDER% to your path to Plist files:
GOOGLE_SERVICE_INFO_PLIST_FROM="${PROJECT_DIR}/%YOUR_CUSTOM_PATH_TO_FOLDER%/${FIREBASE_CONFIG_FILE}.plist"
BUILD_APP_DIR="${BUILT_PRODUCTS_DIR}/${FULL_PRODUCT_NAME}"
GOOGLE_SERVICE_INFO_PLIST_TO="${BUILD_APP_DIR}/GoogleService-Info.plist"
cp "${GOOGLE_SERVICE_INFO_PLIST_FROM}" "${GOOGLE_SERVICE_INFO_PLIST_TO}" 

Add build phase

huynguyen
  • 7,616
  • 5
  • 35
  • 48
  • 4
    To make it consistent : `GOOGLE_SERVICE_INFO_PLIST_FROM="${PROJECT_DIR}/%YOUR_CUSTOM_PATH_TO_FOLDER%/${FIREBASE_CONFIG_FILE}.plist" BUILD_APP_DIR="${BUILT_PRODUCTS_DIR}/${FULL_PRODUCT_NAME}" GOOGLE_SERVICE_INFO_PLIST_TO="${BUILD_APP_DIR}/GoogleService-Info.plist" cp "${GOOGLE_SERVICE_INFO_PLIST_FROM}" "${GOOGLE_SERVICE_INFO_PLIST_TO}"` But this solution really works for multiple scheme sharing same target with different bundle ids as well. – Ollikas Mar 17 '20 at 15:23
  • I am getting the following error : `unexpected EOF while looking for matching `"' ` and ` syntax error: unexpected end of file Command PhaseScriptExecution failed with a nonzero exit code ` – Jerry Okafor Apr 01 '20 at 13:20
  • @huync I am getting error while running this script ${PODS_ROOT}/FirebaseCrashlytics/run What should be the input files path? – venky Jun 13 '20 at 11:50
  • @Ollikas if you have faced the same issue & solved. please let know what is the input files path? I am getting the same error while running the script. – venky Jun 13 '20 at 11:51
35

This worked for me:

Make sure you add the Xcode Crashlytics build phase after Copy Bundle Resources.

bizz84
  • 1,964
  • 21
  • 34
33

I had this in my "Build Phases" and it's works

"${PODS_ROOT}/FirebaseCrashlytics/run"
"${PODS_ROOT}/FirebaseCrashlytics/upload-symbols" -gsp "${PROJECT_DIR}/MyApp/GoogleService-Info.plist" -p ios "${DWARF_DSYM_FOLDER_PATH}/${DWARF_DSYM_FILE_NAME}"
CmoiJulien
  • 659
  • 8
  • 6
  • 1
    Adding `-gsp` and `-p` works for me. I moved the `GoogleService-Info.plist` to a different direcotry, so I have to use `-gsp` to specify the location. – Honghao Z Jun 27 '20 at 23:45
  • This is my choosen solution. I use the CONFIGURATION variable to resolve the target like this: `PLIST="${PROJECT_DIR}/${TARGET_NAME}/Environment/${CONFIGURATION}`/GoogleService-Info.plist" – Max Cruz Jan 04 '21 at 10:55
  • Where did you add these in Build Phases? – thecoolmacdude Jan 20 '22 at 18:12
  • 3
    For Flutter users, I was able to make this work by going to XCode -> "Project Navigator" tab -> Runner -> highlight the Target "Runner" -> "Build Phases" tab -> find the "[firebase_crashlytics] Crashlytics Upload Symbols" step, and change it to `"$PODS_ROOT/FirebaseCrashlytics/upload-symbols" --flutter-project "$PROJECT_DIR/firebase_app_id_file.json" -gsp "$PROJECT_DIR/GoogleService-Info.plist" -p ios "$DWARF_DSYM_FOLDER_PATH/$DWARF_DSYM_FILE_NAME"` (previously it was `"$PODS_ROOT/FirebaseCrashlytics/upload-symbols" --flutter-project "$PROJECT_DIR/firebase_app_id_file.json"`). – markhops Apr 03 '22 at 19:40
  • Update as of November 2022: This doesn't quite work for me, but if I remove the `upload-symbols` and instead put its parameters on the `run` command, it works. The `run` script passes all of its parameters to `upload-symbols`, and apparently throws this error if `run` has no parameters. At least for me. – James Marshall Nov 02 '22 at 00:10
22

Our project only one target, but we need to use two Firebase config files GoogleService-Info-Prod.plist and GoogleService-Info-Dev.plist.

I had this in my "Build Phases" and it works.

if [ "${CONFIGURATION}" = "Release" ]; then
${PODS_ROOT}/FirebaseCrashlytics/run -gsp ${PROJECT_DIR}/RushCard/FirebaseConfig/GoogleService-Info-Prod.plist
else
${PODS_ROOT}/FirebaseCrashlytics/run -gsp ${PROJECT_DIR}/RushCard/FirebaseConfig/GoogleService-Info-Dev.plist
fi
Jay
  • 267
  • 2
  • 7
  • If you are using **SPM** then the script should be as follow: `if [ "${CONFIGURATION}" = "Release" ]; then ${BUILD_DIR%/Build/*}/SourcePackages/checkouts/firebase-ios-sdk/Crashlytics/run -gsp ${PROJECT_DIR}/HERE_SET_YOUR_PROJECT_NAME/SupportingFiles/GoogleService-Info/GoogleService-Info-Prod.plist else ${BUILD_DIR%/Build/*}/SourcePackages/checkouts/firebase-ios-sdk/Crashlytics/run -gsp ${PROJECT_DIR}/HERE_SET_YOUR_PROJECT_NAME/SupportingFiles/GoogleService-Info/GoogleService-Info-Test.plist fi` – nurtugan Aug 25 '22 at 09:01
  • 2
    Slight typo in the SPM suggestion. Should be `if [ "${CONFIGURATION}" = "Release" ]; then ${BUILD_DIR%/Build/*}/SourcePackages/checkouts/firebase-ios-sdk/Crashlytics/run -gsp ${PROJECT_DIR}/HERE_SET_YOUR_PROJECT_NAME/SupportingFiles/GoogleService-Info/GoogleService-Info-Prod.plist else ${BUILD_DIR%/Build/*}/SourcePackages/checkouts/firebase-ios-sdk/Crashlytics/run -gsp ${PROJECT_DIR}/HERE_SET_YOUR_PROJECT_NAME/SupportingFiles/GoogleService-Info/GoogleService-Info-Test.plist; fi` – Cory Loken Nov 25 '22 at 16:53
9

In my case I created New Run Script Phrase above Compile Sources, that's why I always see

Could not get GOOGLE_APP_ID in Google Services file from build environment

When I moved Crashlytic's run script at the end of list bug was disappear. Please look the following screen shot: enter image description here

And article about it is here

Taras
  • 1,485
  • 1
  • 16
  • 31
9

I use multiple configurations for several white-labelled apps. I added a User-Defined variable FIREBASE_SUFFIX and changed my script to the following:

${PODS_ROOT}/FirebaseCrashlytics/run -gsp ${PROJECT_DIR}/Firebase/GoogleService-Info-${FIREBASE_SUFFIX}.plist

NOTE: I use Carthage for firebase here: https://github.com/firebase/firebase-ios-sdk/blob/master/Carthage.md. If you're this same setup, you should use something like this instead (replace the path to where you put your script files):

${PROJECT_DIR}/scripts/run -gsp ${PROJECT_DIR}/Firebase/GoogleService-Info-${FIREBASE_SUFFIX}.plist
Jacob
  • 1,052
  • 8
  • 10
8

Another way is to make sure one plist keeps the original name GoogleService-Info.plist

Different targets meant more work to update CI for me.

This is valid for Xcode 11 at least, not tested on any other versions

  • 2
    How can you be sure it will bind the Dsym to the relevant App then ? GOOGLE_APP_ID are different in the plist files if you have one bundle Id for Test and one for Prod. – Romano Mar 05 '20 at 15:33
6

I was using new Firebase/Crashlytics which beta and getting error "No Google App ID or Google Services file provided" when I try to upload manually dSYMS

Here is command:

/path/to/pods/directory/FirebaseCrashlytics/upload-symbols
-gsp/path/to/GoogleService-Info.plist -p ios /path/to/dSYMs

Then I reliaze there should be space between "-gsp" and path to Google.plist after that It worked.

Ucdemir
  • 2,852
  • 2
  • 26
  • 44
6

The solution for me was removing the call to upload-symbols script.

One of the Crashlytics guides mentions you should add this:

${PODS_ROOT}/FirebaseCrashlytics/run
/path/to/pods/directory/FirebaseCrashlytics/upload-symbols  <- Not needed

I misinterpreted this... the run script already calls upload-symbols so there's no need to add a second call.

Harout360
  • 899
  • 1
  • 9
  • 14
  • I am getting an error: Could not get GOOGLE_APP_ID in Google Services file from build environment – ashwini technopurple Oct 07 '20 at 03:50
  • @ashwinitechnopurple make sure you added the plist from Firebase to your project and that it's also added to the correct app target – Harout360 Oct 09 '20 at 18:36
  • This worked for me. I removed this below line: `"$PODS_ROOT/FirebaseCrashlytics/upload-symbols" --flutter-project "$PROJECT_DIR/firebase_app_id_file.json" ` And added this as the first line: `"$PODS_ROOT/FirebaseCrashlytics/run"` – Sainath A May 01 '22 at 12:38
5

Make sure in Xcode file explorer (i.e on the left side) "GoogleService-Info.plist" is showing. If not you have to drag and drop "GoogleService-Info.plist" in the Xcode panel.

In my case problem is I copy-pasted the file in the project location, due to this file reference is missing in the Project info.

Vivek Bansal
  • 1,301
  • 13
  • 21
4

Well all above answers purpose a possible solution for this issue, in my case GoogleService.plist file was missing from 'Copy Bundle Resources' by adding into it worked in my case..

To check the file goto

Project Directory >> Build Phases >> Copy Bundle Resources

add it add here if you find missing.

Zeeshan Ahmed
  • 834
  • 8
  • 13
3

If you use Xcode 15 (beta as of 2023), you might have updated your project with ENABLE_USER_SCRIPT_SANDBOXING.

The default is YES, and this will cause the issue with Crashlytics during archive.

Go to Build Settings > User Script Sandboxing > Set to No.

samwize
  • 25,675
  • 15
  • 141
  • 186
  • Thanks for this! Since the recommended setting for "User Script Sandboxing" is Yes, is there a different solution? – Joshua Aug 15 '23 at 17:59
2

If these solutions provided above do not work, I solved mine by going to Build phases as shown on this image. Click on plus and add Google plist

Xcode screenshot solution

yendis
  • 318
  • 5
  • 12
1

I was able to fix this by locate where is my GoogleService-Info.plist, copy it to ios folder in Flutter and run with this script

"$PODS_ROOT/FirebaseCrashlytics/upload-symbols" --flutter-project "$PROJECT_DIR/firebase_app_id_file.json" -gsp "$PROJECT_DIR/GoogleService-Info.plist" -p ios "$DWARF_DSYM_FOLDER_PATH/$DWARF_DSYM_FILE_NAME"

Update: I found a better solution:

  • Just upgrade all firebase package to lastest version
  • Remove Crashlytics build script
  • Run flutter clean, flutter pub get
  • pod install (in ios folder)
Kyo Huu
  • 520
  • 7
  • 13
1

I had this issue because I didn't download GoogleService-Info.plist file from Firebase console.

If you have your project on Firebase but missing this file in Xcode, don't worry, you don't need to do the setup again from the beginning. Just go to:
Project Settings > General > Scroll down and in the "Your Apps" panel you will see the file and you can download it and import it in the Xcode project.

1

stackich
  • 3,607
  • 3
  • 17
  • 41
0

I had the same error, also due to the fact that I have multiple bundle identifier and therefore I have a build phase script called Firebase Script (that pinpoints to the correct GoogleService-Info.plist ) that was running after the Crashlytics script. The solution is to run Firebase Script before the Crashlytics script.

Garolla
  • 1
  • 1
0

In my case I had a different name in my file, his name was GoogleService-Enterprise-Info.plis when I change it to the normal name GoogleService-Info.plist, IT WORK FINE !!

0

I faced the same issue for @react-native-firebase/crashlytics

In case you are facing this issue, you probably have missed the 'ios setup' instruction mentioned in below link. Please follow the instruction to fix the issue. https://rnfirebase.io/#generating-ios-credentials

Anupam Chaplot
  • 1,134
  • 1
  • 9
  • 22
0

Just download from Settings of your projects and place for your correct target which you are running.

plist file

Manish
  • 608
  • 1
  • 11
  • 23
0

This error would be shown if there is a space in your project name or in the path of your project.

Read more in this GitHub Issue

Yaman KATBY
  • 1,814
  • 10
  • 24
  • Thanks, but this didn't help for me. In my case there is no spaces in path to the project, but still having this error. – Argus Apr 09 '21 at 12:28
0

Additionally to other answers..

I faced that problem with exact same error message and in my case everything was ok with file GoogleService-Info.plist except that it was genereated with wrong Bundle ID for application (it was changed in XCode much later than initial Firebase setup happened), so I had to create new app in Firebase Console with correct Bundle ID (it's not able to edit) and download new GoogleService-Info.plist

Pavel Sokolov
  • 104
  • 1
  • 6
0

If you are using one of the popular build scripts going around for handling multiple different environments, it is probably useful to know that you should use a different GoogleService-Info.plist destination based on the target platform:

// iOS
PLIST_DESTINATION=${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app

// watchOS
PLIST_DESTINATION=${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.appex

// macOS
PLIST_DESTINATION=${BUILT_PRODUCTS_DIR}/${CONTENTS_FOLDER_PATH}/Resources
budiDino
  • 13,044
  • 8
  • 95
  • 91
-1

Ultimate guide:

  1. Assure that in Runner folder you have file GoogleService-Info.plist and it is attached in your project

  1. If you don't have this file go to Firebase Console, add you IOS app and download the GoogleService-Info.plist file, then add it to you project's Runner folder by XCode.

  2. If there is no such file in XCode but it exists physically in the folder then right click on Runner folder (in Runner project) -> Add files to Runner -> Select that file

  3. If you want to use multiple flavors add ENV_SUFFIX in Runner (target) -> Build Settings -> User-Defined (on the bottom) 4

  4. Still in the target's Runner change tab to Build Phases -> Press Plus button -> New Run Script Phase -> Name it as Copy GoogleService-Info.plist and add this line cp Runner/GoogleService-Info_${ENV_SUFFIX}.plist Runner/GoogleService-Info.plist IMPORTANT! This script has to be before Initialize Crashlytics step or any other Firebase related script (you can drag it to the top) enter image description here

  5. Add other GoogleService-Info.plist files with suffix for the env. In my case those would be the _dev _prod and _tst files from the first screen shot

  6. Enjoy multiflavor app

-4

Try downgrading, it worked for me! I used: 'Fabric', '1.9.0' 'Crashlytics', '3.12.0'

  • 6
    Everybody should always use the latest version of stable software. Old version software can have critical bugs and security issues. – Edgar Froes Jan 25 '20 at 04:38