Step-by-Step Guide on Firebase Crash Reporting

To get  complete crash-report whenever your app crashes. In Simple words, Firebase Crash Reporting will let you know the reason of crash  along with line number in your view controller or any class.






I’m assuming you have a project, where you want to add Firebase Crash Reporting.

First thing first, You need Cocoapod installed on your Mac and a working project (or, any iOS Single View Application).

Step 1. Login into your Firebase Console




Click on ‘Create New Project’  and then pass on relevant information about your app (like, Your App Name and its country).









Step 2. Now, you are on Firebase Dashboard


As you can see there are several Firebase service, but we are quietly interested in Firebase Crash Reporting




Next, they will ask you to choose your platform (Obviously, it’s iOS)






When you get into it, there is form like window pops up.











Where, you have to pass on bundle id of your app. Rest two are optional which you can ignore.

So, From I can get my Bundle Id ?
Answer is, You have to move on to you app and select your Project > General and there you go Bundle Identifier under Identity section.



Say, I have com.innovationm.FirebaseCrashReportingDemo  and it could be different (as, its Projects Dependent).

Step 3.
Now, you have to add Google Services Info.plist file which has all the credentials and private identifiers which Firebase will use for internal purpose (Doesn’t make sense, still you have to add as Google Developer is asking you to do that 😀 ).











So, drap and drop the GoogleService-Info.plist in your xcode.

Suggestion : If your file name starts with  GoogleService-Info(1).plist  then, you should omit (1) from the file name. As, Firebase expects only GoogleService-Info.plist as its configuration file name. Else, it will cause confusion and pops you runtime error.

Step 4.
Now, they will ask you to install pod of Firebase Core (further, Firebase Crash). As, these are the dependencies which we need in this project.
In simple words, we are going to use Firebase so we need to integrate firebase framework (or, library) in your project.
So, Cocoapod will do it for us.












Open Terminal (CMD+Space and type Terminal)  and type cd [Path_Of_Your_Project] and return key.
There is a shortcut to get the path of project directory.

Tips : Select your Project Directory in Finder and drag-drop to Terminal itself. It will give you the path of dropped directory.

Step 4.1 :









Step 4.2 :
Type Pod init and return key.









Step 4.3 :
That makes a Podfile in root directory of your project.







Step 4.4 : And, Open it in any Text Editor (as, I’m addict of Sublime so, I’ll use it). And, paste the pod file name and save the file.








Alert : Make sure, you add these two lines in between Line 6 and 12 (as per image).

Step 4.5 :
Type pod install and install the dependencies which you have mention.









Step 4.6 :
Close terminal and open your .workspace in your project directory.







Alert : If you open .xcodeproj file then you won’t get pod dependencies in your project. And, it will throw error that dependencies files are not found.

Step 5.
Ultimately, we have a project which has Firebase Crash Reporting .
Now, configure Firebase in AppDelgate.swift











So, AppDelegate.swift is like




Step 6.
Next part is bit tricky, as we have to write a piece of script in Build Phase.
First, go to your Project Screen.
screen-shot-2016-12-31-at-4-40-25-amAnd, choose Build Phase and click on + Button (just below Capability)

There you have options to choose.




Next, we have a blank script screen with some default text.
screen-shot-2016-12-31-at-4-43-06-amSo, we have to add these lines in script box.

# Replace this with the GOOGLE_APP_ID from your GoogleService-Info.plist file

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

Though, we have to replace bold text i.e GOOGLE_APP_ID and /Path/To/ServiceAccount.json with ‘projects’ value.

First, we will get Google App Id from Info.plist which we have downloaded (i.e. GoogleService-Info.plist).






And, Next we need ServiceAccount JSON file which we’ll get it from Firebase Console.

Click on Setting (Gear Button which is on right side of OverView Button) >  Service Account (last Tab) > Crash Reporting > Generate Private Key Button.
screen-shot-2016-12-31-at-4-50-24-amDownload the file and rename whatever you want. Say, mine is firebasecrashreport.json .

And, paste in root folder of your project. After doing this, drag and drop it to xcode project.









So, My Script would be like,

# Replace this with the GOOGLE_APP_ID from your GoogleService-Info.plist file

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

FirebaseCrashReportingDemo is the name of my project and respective to it firebasecrashreport.json, which makes my absolute path such.

Congratulations, you’re done with Firebase Crash Reporting.

Step 7.
Testing and Logging in Firebase Console.
Step 7.1 : Add a line of statement which make a crash.

fatalError() will do crash it for you.









Step 7.2 : Launch your app and it will crash.
Step 7.3 : Comment the crash Line.
Step 7.4 : Launch your App (It will send the log to Firebase Console).
After 2-3 Minutes, it will log into Firebase Console.

 Initially, it will be like





Click on Error, and it will move you to Crash Reporting Panel.
screen-shot-2016-12-31-at-5-16-14-amIt say, we are crashing at line number 17 for ViewController.swift screen.

Is it true ?









Yes, we have a buggy code at line number 17 and that makes sense.
screen-shot-2016-12-31-at-5-16-14-amscreen-shot-2016-12-31-at-5-32-36-amAdditional Feature

You can send custom logs to Firebase console using FIRCrashMessage(“TYPE_YOUR_MESSAGE”) method.

Further Reference

Leave a Reply