/ firebase

Implementing Crash Reporting into your Android App

To be continue the posts of Firebase series, today I have a new post about Crash Reporting that a feature of Google Firebase. In this post I have two main content is introduce of Crash Reporting and how to implement Crash Reporting into your android applications.

What is Crash Reporting?

Crash Reporting is a feature of Google Firebase. According to the Firebase docs: Comprehensive and actionable information to help diagnose and fix problems in your app.

Crash Reporting creates detailed reports of the errors in your app. Errors are grouped into clusters of similar stack traces and triaged by the severity of impact on your users. In addition to automatic reports, you can log custom events to help capture the steps leading up to a crash.

Implement Crash Reporting into your Android application

Before add Crash Reporting into your Android app you must add Android app into Firebase console and setup Firebase in Android app. You can read more detail at Firebase docs.

Now you can add Crash Reporting dependences to you app. Add this line into your module build.gradle file

compile 'com.google.firebase:firebase-crash:9.4.0'

Create your first crash

Firebase Crash Reporting automatically generates reports for fatal errors (or uncaught exceptions). However, you can also generate reports in instance where you catch an exception but still want to report the occurrence. To report such an error, you can follow these steps:

  1. Add a call to the static report method in the main activity: FirebaseCrash.report(new Exception("My first Android non-fatal error"));
  2. Launch the app.
  3. In adb logcat or AndroidStudio logs, look for the message confirming that Crash Reporting is enabled.
  4. Look for the message confirming a report was sent
  5. Error take up 20 minutes to show up in the Crash Reporting console. Check back to see your report there.

Crash Reporting console

Create custom logs

You can use Crash Reporting to log custom events in your error reports and optionally the logcat. If you wish to log an event and don’t want logcat output, you only need to pass a string as the argument, as shown in this example:

FirebaseCrash.log("Activity created");

If you want to create logcat output, you must also apply the log level and a tag:

FirebaseCrash.logcat(Log.ERROR, "tag", "Message");

Conclusion

Crash Reporting is a beta feature of Google Firebase. I think Crash Reporting will be approve in the future to be a better. You can get complete code in my github: Here