Firebase

Firebase – Crash Reporting

 

Introduction

  • Crash Reporting seems to be an important factor nowadays, as we are less determined about what error can occur on which device model or which Android Version. There are few crash reporting tools available in the market, like ACRA, Fabrics Crashalytics, etc. But this Firebase is something different which made me to write this blog for getting started with it.
  • Firebase Crash Reporting is a comprehensive tool to receive detailed information about the Crash.

Why to switch over it ?

Yes, this is the question I always ask, which boosts me to get started with. So, here are some strong reasons:

  • You can prioritize the reports by Frequency of crash
  • You can prioritize the reports by Impact
  • You get detailed report that includes:
    • device characteristics
    • device circumstances
    • stack trace and much more
  • You can collect crash report even when app is offline..!!

Getting started

Pre-requisites

  • Android Studio 1.5 or above
  • Google Play Services 9.0.2 or above.

Add Firebase to your app

  1. Go to Firebase console and click on “CREATE NEW PROJECT”. Fill the “Project Name” and Select Country, then click on “CREATE PROJECT”
    cropped1
  2. Click on “Add Firebase to your Android app”
    cropped2
  3. Enter Package name and Debug signing certificate SHA-1(Optional) and click on “Add app” button
    cropped3
  4. Google-services.json file will be downloaded. Go to Android Studio and Switch to the Project view in Android Studio to see your project root directory. Move the google-services.json file you just downloaded into your Android app module root directory.
    cropped4
  5. The Google services plugin for Gradle loads the google-services.json file you just downloaded. Modify your build.gradle files to use the plugin.
  6. Add the following lines, to your Project-level build.gradle (/build.gradle):
    buildscript {
    dependencies {
    // Add this line
    classpath 'com.google.gms:google-services:3.0.0'
    }
    }
    
  7. Add the following lines to the bottom of your App-level build.gradle:
    apply plugin: 'com.google.gms.google-services'
    
  8. Add the following dependencies, to your App-level build.gradle
    compile 'com.google.firebase:firebase-crash:9.0.2'
    
  9. Finally, press “Sync now”.

Code

No code at all..!!! I am not kidding.. 🙂 Firebase Crash Reporting automatically generates reports for errors. So, just sit back and relax!

Testing

Still if you want you can generate report for testing purpose. Add below line to your activity:

FirebaseCrash.report(new Exception("My first Firebase crash report."));

And run the app.
According to the Firebase article:
Errors take up to 20 minutes to show up in the Crash Reporting console. Check back to see your report there.

To see the report, Go to Firebase console, Select Your Project and on the Left Side Menu, Click on Crash.

cropped 2

You will see the report as below:

cropped 1

Important Points to remember

Apart from Firebase.report(Exception exception), you can also play with other features like.

  • FirebaseCrash.log(String message): Enables a smart way to log. It will not be shown in Android Monitor Logcat, but it will appear in Crash Report.
  • FirebaseCrash.logcat(Log.XXX, String tag, String message): yet another way to log. This log will appear in both Android Monitor Logcat and Crash Report.

Conclusion

Now you see, integrating crash reporting is become now so easy. Cool, now get your hands on it. We have used firebase crash reporting in some of our applications and We are really impressed with the detailing of the reports. Though it’s in beta, you should try!

Hope you enjoyed learning Firebase Crash Reporting. Happy Firebasing 🙂

Want to work with us? We're hiring!
  • Finava Vipul

    Nice post! Congrats!

    • Chintan Soni

      Thanks 🙂

  • Raghav Satyadev

    Sir, the official documentation says that if we have extended Application class and implemented Database or Shared Preference logic then App might have problems because of this reporting. Can you explain more about this? as i have implemented Volley’s ApplicationController in my app which extends Application. it also initialize Custom SQLiteHelper after starting the app.

    Another thing is they asked to upload mapping.txt somewhere which will Deobfuscate Proguard labels , I can’t understand where to upload it, and what help will it give. Can you throw some light on this issue?