8

I am trying to implement crash reporting with firebase. I followed the documentation here. And renamed the downloaded son file to ServiceAccount.json. Then copied it to project directory. Also changed the script. Now my build phase run script looks like

# Replace this with the GOOGLE_APP_ID from your GoogleService-Info.plist file
GOOGLE_APP_ID=1:.....#my app id

# Replace the /Path/To/ServiceAccount.json with the path to the key you just downloaded
"${PODS_ROOT}"/FirebaseCrash/upload-sym "ServiceAccount.json"

But when I try to build the project its giving build error

Unexpected argument 'ServiceAccount.json'
usage: /Users/<full path>/Pods/FirebaseCrash/upload-sym [-h] [-v] [-w|-e]
Command /bin/sh failed with exit code 2

Whats wrong with my steps?

Sahil Kapoor
  • 11,183
  • 13
  • 64
  • 87
Johnykutty
  • 12,091
  • 13
  • 59
  • 100
  • where to run it . As I am running and getting error. So what is the folder name here or I have make changes in this command path/to/pods/directory/FirebaseCrashlytics/upload-symbols -gsp /path/to/GoogleService-Info.plist -p ios /path/to/dSYM – Rover Jun 24 '21 at 06:00

13 Answers13

22

This is the script I use in my practice project.

JSON_FILE=${SRCROOT}/*****/ServiceAccount.json
GOOGLE_APP_ID=1:**********:ios:*********

defaults write com.google.SymbolUpload version -integer 1

JSON=$(cat "${JSON_FILE}")
/usr/bin/plutil -replace "app_${GOOGLE_APP_ID//:/_}" -json "${JSON}" "$HOME/Library/Preferences/com.google.SymbolUpload.plist"
"${PODS_ROOT}"/FirebaseCrash/upload-sym

If your JSON file is in the project folder "XYZ" then you only need this "JSON_FILE=${SRCROOT}/XYZ/ServiceAccount.json" or if it is in a subFolder of XYZ then like this "JSON_FILE=${SRCROOT}/XYZ/subFolder/ServiceAccount.json"

And set you GOOGLE_APP_ID and that is it. sorry for bad English. Hope It helps :)

Abdul Rehman
  • 2,386
  • 1
  • 20
  • 34
  • 2
    This is working.. but I didn't get why in the documentation, its saying to pass the json file path as parameter – Johnykutty Aug 30 '16 at 03:42
  • I am not sure about that but my wild guess is that this is what we are doing in this script. Take a look of the first line "JSON_FILE=${SRCROOT}/*****/ServiceAccount.json". It is getting the path of the JSON file and saving it into the "JSON_FILE" variable or what ever this is – Abdul Rehman Aug 30 '16 at 04:15
  • And after that in third line " JSON=$(cat "${JSON_FILE}") " use the same " JSON_FILE " and creating file that is what I think (wild guess). – Abdul Rehman Aug 30 '16 at 04:24
  • And in the second last line replacing the "GOOGLE_APP_ID" and setting -json file to "JSON" and setting Plist file. That is all I know. – Abdul Rehman Aug 30 '16 at 04:28
  • 1
    I could understand what the script, but didn't get why the documentation is misleading. My be not updated the docs. – Johnykutty Aug 30 '16 at 04:37
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/122155/discussion-between-johnykutty-and-abdul-rehman-warraich). – Johnykutty Aug 30 '16 at 04:41
  • @Abdul Rehman Warraich,Johnykutty will you please post complete script that you created – nivritgupta Sep 29 '16 at 06:51
  • @nivritgupta It is complete script which I used. – Abdul Rehman Sep 29 '16 at 16:20
  • @Abdul Rehman Warraich i am doing something Wrong..... here is my complete script JSON_FILE=${SRCROOT}/Users/nivritgupta/Desktop/GuideTurbo-e81e9b7509a9.json GOOGLE_APP_ID=1:45221286783:ios:a1847be572be1f70 defaults write com.google.SymbolUpload version -integer 1 JSON=$(cat "${JSON_FILE}") /usr/bin/plutil -replace "app_${GOOGLE_APP_ID//:/_}" -json "${JSON}" "$HOME/Library/Preferences/com.google.SymbolUpload.plist" "${PODS_ROOT}"/FirebaseCrash/upload-sym – nivritgupta Sep 29 '16 at 17:03
  • @nivritgupta I think your file path of JSON file is not correct. let me know that where you place your JSON file. – Abdul Rehman Sep 30 '16 at 04:38
  • @nivritgupta " ${SRCROOT} " give you the root path of the project directory. – Abdul Rehman Sep 30 '16 at 04:45
  • @nivritgupta so what you have to do is only locate where is the JSON file in your project folder. like if your JSON fie in main folder then it look like this " JSON_FILE=${SRCROOT}/ServiceAccount.json " if in subfolder then like this " JSON_FILE=${SRCROOT}/TestProject/ServiceAccount.json " – Abdul Rehman Sep 30 '16 at 04:51
  • @Abdul Rehman Warraich my JSON File located in main desktop JSON_FILE=/Users/nivritgupta/Desktop/Firebase/Firebase/GuideTurbo-e81e9b7509a9.json after that i am able to run this script and trying to crash the app but did not received anything in firebase backend .. if i follow your instruction then i received this error .. check the screenshot https://www.evernote.com/l/AUrWd5p5wxpM8autqIjBS_TohN-FGYu1Rqo – nivritgupta Sep 30 '16 at 05:47
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/124612/discussion-between-abdul-rehman-warraich-and-nivritgupta). – Abdul Rehman Sep 30 '16 at 06:03
  • I am not using pod. what should i write instead of "${PODS_ROOT}"/FirebaseCrash/upload-sym – Swati Dec 19 '16 at 09:49
  • "${SRCROOT}"/CrashReportingKey/ServiceAccount.json ... Source root brings the path to your project, CrashReportingKey is the folder inside it , if you are not using pods , use SRCROOT to get your project path , then create a folder and inside will be the json , if you dont want to create a folder , just "${SRCROOT}"/ServiceAccount.json would work , put your json inside the base path of your project – Ramiz Girach May 31 '17 at 06:15
6

This works for me. Just removed " from method described on Firebase docs.

GOOGLE_APP_ID=1:**********:ios:************
"${PODS_ROOT}"/FirebaseCrash/upload-sym ${SRCROOT}/******/GoogleCrashKey.json
Sahil Kapoor
  • 11,183
  • 13
  • 64
  • 87
3

It seems that upload-sym script has been changed to take one parameter since FirebaseCrash 1.0.7.

Check your FirebaseCrash pod version by pod outdated and update it if you are using older one.

Hiron
  • 1,457
  • 1
  • 13
  • 12
  • I have updated it and the code from the firebase site https://firebase.google.com/docs/crash/ios worked . – jamil Sep 29 '16 at 16:31
3

In my case, script could not find the 'FirebaseCrash/upload-sym' because the Google article only recommend us add 'Firebase/Core' to Podfile.

And i added: 'Firebase/Crash' library then it worked, hope this help!

ChenHuang
  • 382
  • 2
  • 11
3

Abdul's solution worked for me but I had to replace upload-sym with upload-sym-util.bash in the script, so it ended up looking like this:

JSON_FILE=${SRCROOT}/Pods/FirebaseCrash/ServiceAccount.json
GOOGLE_APP_ID=1:*:ios:*

defaults write com.google.SymbolUpload version -integer 1

JSON=$(cat "${JSON_FILE}")
/usr/bin/plutil -replace "app_${GOOGLE_APP_ID//:/_}" -json "${JSON}" "$HOME/Library/Preferences/com.google.SymbolUpload.plist"
"${PODS_ROOT}"/FirebaseCrash/upload-sym-util.bash
3

I just changed /FirebaseCrash/upload-sym to /FirebaseCrash/upload-sym-util.bash in my script, it worked

GOOGLE_APP_ID=1:1234567830:ios:7sjghd66373hbdd2 "${PODS_ROOT}"/FirebaseCrash/upload-sym-util.bash "/Users/iosteam/Documents/MYLES-iOS-a86994a092e8.json"

Sourabh Shekhar
  • 157
  • 1
  • 12
2

Update: Latest FirebaseCrash has fixed this and usage is now different.

The instructions are wrong. You need to manually generate PLIST file, but only ONCE. The following is my addition to Abdul's script:

# Replace this with the GOOGLE_APP_ID from your GoogleService-Info.plist file
GOOGLE_APP_ID=1:*:iOS:*

# Insert this code BETWEEN the GOOGLE_APP_ID declaration and the
# call to FirebaseCrash/upload-sym, to generate PLIST file if needed
# Note the PLIST_FILE location is hard-coded in firebase script, do not change
PLIST_FILE="${HOME}/Library/Preferences/com.google.SymbolUpload.plist" # DO NOT CHANGE
if [ ! -f "${PLIST_FILE}" ]; then
  JSON_FILE="${PODS_ROOT}/FirebaseSymbolUploadKey.json"  # Change to location of your file
  defaults write com.google.SymbolUpload version -integer 1  # Required by script
  JSON=$(cat "${JSON_FILE}")
  /usr/bin/plutil -replace "app_${GOOGLE_APP_ID//:/_}" -json "${JSON}" "${PLIST_FILE}"
fi

# Instructions WRONG, don't pass any args, script hard-codes where it looks
# for credentials, which is handled by the JSON conversion above
"${PODS_ROOT}"/FirebaseCrash/upload-sym
Khaled Annajar
  • 15,542
  • 5
  • 34
  • 45
Speedy99
  • 1,691
  • 15
  • 15
1

The latest firebase crash upload-sym script can find the service account json without specifying any path, just place it in the same folder next to your Xcode xcproject file.

If you're using CocoaPods, something like this simple script example works:

GOOGLE_APP_ID=1:1234567890:ios:ab123cd456ef789
"${PODS_ROOT}"/FirebaseCrash/upload-sym crash-service-account.json

If you don't want to upload symbols every time you run, then use the following script instead, to reduce your compile time a bit:

if ["${CONFIGURATION}" != "Debug" ]; then
GOOGLE_APP_ID=1:1234567890:ios:ab123cd456ef789
"${PODS_ROOT}"/FirebaseCrash/upload-sym crash-service-account.json
fi
Dhiraj Gupta
  • 9,704
  • 8
  • 49
  • 54
0

First : add to file ServiceAccount ".json" --> ServiceAccount.json

and copy that file to root folder of you project.

Second : set this code in run script in "Build Phases"

GOOGLE_APP_ID= copy here your "GOOGLE_APP_ID" from GoogleService-Info.plist

"${PODS_ROOT}"/FirebaseCrash/upload-sym  "${ROOT}"ServiceAccount.json
  • pay attention that GoogleService-Info.plist have the "API_KEY"

    if not go to firebase and download this file again.

Roei Nadam
  • 1,780
  • 1
  • 15
  • 33
0

In my case I did all the steps same as firebase crash report tutorial given, still I was getting same ERROR. Later on, I realised once I implemented Google Analytics before Firebase Analytics and Crash Report on the same project. So I was getting the crash, For that I have removed the Google Analytics from the Podfile and re-installed the pod by pod install command in terminal.

Manab Kumar Mal
  • 20,788
  • 5
  • 31
  • 43
  • Not getting solution for this as I am not getting where to run it where to run it . As I am running and getting error. So what is the folder name here or I have make changes in this command path/to/pods/directory/FirebaseCrashlytics/upload-symbols -gsp /path/to/GoogleService-Info.plist -p ios /path/to/dSYM – Rover Jun 24 '21 at 06:01
0

I had the same error; caused by me putting the upload-sym snippet into the Post-Action of "Archive" instead of "Build"

But upload-sym does not work in Archive Post-Action. It requires environment variables that is only available in Build actions.

(p.s. I didn't want it to upload every time I build, just every time I make a build for the AppStore.)

Billy
  • 437
  • 1
  • 6
  • 13
0

I have FirebaseCrash 1.0.6. And my solution was just use

"${PODS_ROOT}"/FirebaseCrash/upload-sym

without any parameters.

Yaroslav Babenko
  • 234
  • 3
  • 13
0

I faced the same issue. i have following lines in my podfile :

pod 'Fabric', '~> 1.7.2' pod 'Crashlytics', '~> 3.9.3'

I have resolved the issue by replacing above lines in pod file by following :

pod 'Firebase/Crash'

Tanvi Jain
  • 917
  • 2
  • 7
  • 19
  • This is no longer recommended. `'Firebase/Crash'` has been replaced with `pod 'Fabric'` and `pod 'Crashlytics'` – Adil Soomro Jan 19 '20 at 17:03