Firebase for Android: Crashlytics

How to report a crash in Android via Firebase Crash Reporting

Firebase Crashlytics is a lightweight, realtime crash reporter that helps helps you track, prioritize, and fix stability issues that erode your app quality. Crashlytics saves you troubleshooting time by intelligently grouping crashes and highlighting the circumstances that lead up to them.

Crashlytics is the new, primary crash reporter for Firebase. If your app uses Firebase Crash Reporting, there's good news: Crashlytics offers enhanced crash reporting with nearly the same setup process you're used to

Key capabilities are:

  • Curated crash reports. Crashlytics synthesizes an avalanche of crashes into a manageable list of issues, provides contextual information, and highlights the severity and prevalence of crashes so you can pinpoint the root cause faster.
  • Enhanced environment info. Crashlytics allows you to filter reports by operating system, version, hardware configuration, and more. Find out if your app is crashing more frequently on a particular manufacturer's devices, with certain API versions, or even in a specific screen orientation.
  • Realtime alerts. Get realtime alerts for new issues, regressed issues, and growing issues that might require immediate attention.

To get started, you need a Firebase app with Firebase Crashlytics enabled.

If you're using the latest version of Android Studio (version 2.2 or later), it's recommend using the Firebase Assistant to connect your app to Firebase. The Firebase Assistant can connect your existing project or create a new one for you and automatically install any necessary gradle dependencies.

To open the Firebase Assistant in Android Studio:

  1. Click Tools > Firebase to open the Assistant window.
  2. Click to expand one of the listed features (for example, Analytics), then click the provided tutorial link (for example, Log an Analytics event).
  3. Click the Connect to Firebase button to connect to Firebase and add the necessary code to your app.

Following steps is nesessary to add the Crashlytics SDK to your project.

Add the Crashlytics repositories and dependency to your project-level build.gradle file:

buildscripts {
    repositories {
        // ...
        maven {
           url 'https://maven.fabric.io/public'
        }
    }
    dependencies {
        // ...
        classpath 'io.fabric.tools:gradle:1.24.4'
    }
}

allprojects {
    // ...
    repositories {
       // ...
       maven {
           url 'https://maven.google.com/'
       }
    }
}

Add the Crashlytics dependencies to your app-level build.gradle:

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

dependencies {
    // ...
    compile 'com.google.android.gms:play-services:11.4.2'
    compile('com.crashlytics.sdk.android:crashlytics:2.7.1@aar') {
       transitive = true
    }
    compile 'com.google.firebase:firebase-core:11.4.2'
}

Once you've added the SDK to your app, Crashlytics automatically gets to work listening for and collecting crash reports.

Finally, enable Crashlytics in the Firebase console by clicking Set up Crashlytics.

To test Firebase Crashlytics add following snippet somewhere in your code

Crashlytics.getInstance().crash();

The report should appear in the Firebase console within five minutes.

To give yourself more context for the events leading up to a crash, you can add custom Crashlytics logs to your app. Crashlytics associates the logs with your crash data and makes them visible in the Firebase console.

Use Crashlytics.log to help pinpoint issues. Crashlytics.log can write logs to a crash report and with Log.println(), or just to the next crash report.

Crash report and Log.println:

Crashlytics.log(int priority, String tag, String msg);

Crash report only:

Crashlytics.log(msg);
comments powered by Disqus