Firebase Crashlytics is a lightweight, realtime crash reporter that 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.
- Quickly pinpoint the root cause of crashes
Crashlytics intelligently groups an avalanche of crashes into a manageable list of issues. It also provides information on why a crash occurred and what happened leading up to it. With this insight, you can uncover the root cause of crashes more quickly.
- Understand what issue to tackle first
Crashes are prioritized by impact on actual users so you know how best to triage effort for fixing bugs.
- Never miss a critical crash
-Get realtime alerts for new issues, regressed issues, and burgeoning issues that might require immediate attention, no matter where you are.
Get started with Firebase Crashlytics :
This quickstart describes how to set up Firebase Crashlytics in your app with the Firebase Crashlytics SDK, so you can get comprehensive crash reports in the Firebase console.
Step 1: Set up Crashlytics in the Firebase console
- Click Crashlytics in the left-hand nav panel of the Firebase console.
- If your Firebase project has multiple apps registered in it, select the app you just added from the dropdown next to Crashlytics in the top bar of the console.
- Click Add SDK.
Step 2: Add Firebase Crashlytics to your app
- In your project-level build.gradle file, add the Crashlytics Gradle plugin as a buildscript dependency:
- In your app-level build.gradle file, apply the Crashlytics Gradle plugin:
Step 3: Initialize Crashlytics
For an optimal experience with Firebase Crashlytics, we recommend adding the Firebase SDK for Google Analytics to your app in addition to the Firebase Crashlytics SDK. Make sure you add Google Analytics version 17.2.3 or later in order to get real time crash-free users and breadcrumbs.
- In your app-level build.gradle, add dependencies for Google Analytics and Crashlytics
- Optional: Firebase Crashlytics offers crash reporting for apps built using the Android Native Development Kit (NDK). If your app uses the NDK, you can configure Crashlytics to report crashes that occur in your app’s underlying NDK libraries. Visit the NDK crash reporting documentation to learn how.
Step 4: Run your project
Finally, run your app. Your device logs display the Firebase verification that initialization is complete.
- Test your Crashlytics setup by forcing a crash in the Firebase console.
- Customize your crash report setup by adding opt-in reporting, logs, keys, and tracking of non-fatal errors.
Force a crash to test your implementation :
You don’t have to wait for a crash to know that Crashlytics is working. To force a crash, add a button to your app’s MainActivity:
To test the implementation, press the button in your app to force the crash, then reopen your app so that Crashlytics can send the crash report to Firebase. It may take up to five minutes for the report to appear in the Firebase console.
Enable Crashlytics debug logging :
If your forced crash didn’t crash, crashed before you wanted it to, or you’re experiencing some other issue with Crashlytics, you can enable Crashlytics debug logging to track down the problem.
To enable debug logging on your development device, set an adb shell flag before running your app:
To view the logs in your device logs, run:
To disable debug logging, set the flag back to INFO:
Customize your Firebase Crashlytics crash reports :
This guide describes how to customize your crash reports using the Firebase Crashlytics SDK. By default, Crashlytics automatically collects crash reports for all your app’s users (you can turn off automatic crash reporting and enable opt-in reporting for your users instead). Crashlytics provides four logging mechanisms out of the box: custom keys, custom logs, user identifiers, and caught exceptions.
Add custom keys :
Custom keys help you get the specific state of your app leading up to a crash. You can associate arbitrary key/value pairs with your crash reports and see them in the Firebase console.
Use the setCustomKey instance method to set key/value pairs:
You can also modify the value of an existing key by calling the key and setting it to a different value. For example:
Add custom log messages :
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 displays them in the Crashlytics page of the Firebase console, under the Logs tab.
Set user identifiers :
To diagnose an issue, it’s often helpful to know which of your users experienced a given crash. Crashlytics includes a way to anonymously identify users in your crash reports.
To add user IDs to your reports, assign each user a unique identifier in the form of an ID number, token, or hashed value:
If you ever need to clear a user identifier after you set it, reset the value to a blank string. Clearing a user identifier does not remove existing Crashlytics records. If you need to delete records associated with a user ID, contact Firebase support.
Report non-fatal exceptions :
In addition to automatically reporting your app’s crashes, Crashlytics lets you record non-fatal exceptions and sends them to you the next time your app launches.
Use the recordException method to record non-fatal exceptions in your app’s catch blocks. For example:
Note: Crashlytics only stores the most recent eight recorded exceptions. If your app throws more than eight exceptions, older exceptions are lost.
Enable opt-in reporting :
By default, Crashlytics automatically collects crash reports for all your app’s users. To give users more control over the data they send, you can enable opt-in reporting for your users by disabling automatic collection and initializing Crashlytics only for selected users:
- Turn off automatic collection with a meta-data tag in your AndroidManifest.xml file:
- Enable collection for select users by calling the Crashlytics data collection override at runtime. The override value persists across launches of your app so Crashlytics can automatically collect reports for future launches of that app instance. To opt out of automatic crash reporting, pass false as the override value. When set to false, the new value does not apply until the next run of the app.
Manage Crash Insights data :
Crash Insights helps you resolve issues by comparing your anonymized stack traces to traces from other Firebase apps and letting you know if your issue is part of a larger trend. For many issues, Crash Insights even provides resources to help you debug the crash.
Crash Insights uses aggregated crash data to identify common stability trends. If you’d prefer not to share your app’s data, you can opt-out of Crash Insights from the Crash Insights menu at the top of your Crashlytics issue list in the Firebase console.
Firebase Console Setup :
Step 1: let’s create a new project in Firebase Console here. Just set the project name and accept the Firebase terms. You can also select another Analytics location and set a specific Project ID.
Add a Project to Firebase Console :
Step 2: Let’s register our app in Firebase. We just need our package details :
Step 3: download the google-services.json file and place in Android app module root directory.
That’s it! Now run your app now and it is successfully configured with firebase Crashlytics! We can test the crash by adding force crash code as discussed in the above line in Activity/Fragment to force a crash.
Track Crashes in Console :
Last 7 days Crash report List :
New issue alerts let you know the first time a new crash has occurred. We filter out the noise of repeated crashes, but give you the full stream of unique crashes by stack trace grouping. These alerts are turned off by default to avoid over inundating you, because as your app grows, you could get tons of alerts for every new version. We recommend turning these on for teams interested in knowing about every new type of crash, and for QA teams chasing down crashes found in testing versions of their apps.
Regression detection alerts you when a previously closed issue re-occurs in a new app version, which is a signal that something else may be awry and you should pay close attention to it.
Trending issues digest is sent out to developers in two instances 1) When Crashlytics detects a new crash is beginning to gain momentum (called emerging issues) 2) When Crashlytics detects new top crashes that have climbed to close to the top of your issue list recently (called trending issues). This daily email is on by default, and is a great way to keep track of emerging issues in your app.
Firebase Crashlytics offers several channels to receive the above alerts. The first two channels are email and in-console alerts.
To setup these alerts:
Click 🔔 Firebase alerts in the upper-right corner of the Firebase console
Click the gear icon ⚙️ for settings
Choose the project that you want to receive email alerts for
Check relevant boxes to choose whether you’d like alerts in the Firebase Console, over email, or both