Crash Reporting and Realtime Analytics of Android App with Fabric Crashlytics

SHISHIR
PROGRAMMING LITE
Published in
6 min readJul 9, 2018

Now a days market has become very competitive. That’s why we must need to care the users by providing the bug-free builds, or fix the bugs without time delay. So we have to track the crashes which are happened to the user’s device. And Crashlytics will help you discover these problems very easily.

Crashlytics is one of the Fabric tools and it is completely free of charge. Twitter released Fabric in 2014. On January, 2017 Google took Fabric from Twitter and added as a feature of Firebase. You can say Crashlytics one of the best crash reporting tools. Some Key points of Crashlytics.

  • Crashlytics gives you powerful crash reporting, with one additional click. You can also enable real-time analytics that help you understand what’s happening in your app.
  • It’s very easy and almost automatic process to set up the Crashlytics
  • Crashlytics is a wonderful tool for crash analytics, it is quick, provides nice summary and has almost everything we need to know about the crash.
  • It shows details like number of crashes, percentage of crash-free users, and which users are impacted by each crash.

In this tutorial we will add Fabric’s Crashlytics to an Android app, generate error and see the error report in Crashlytics. We will go over the following steps:

  1. Create Fabric Account.
  2. Create new Project in Android Studio.
  3. Install Fabric Plugins in Android Studio.
  4. Integrate Crashlytics in Android app.
  5. Force a test crash and check error reports in Crashlytics dashboard.

Create Fabric Account

First of all you will need to create a free Fabric account at fabric.io. After creating account, it will send you a confirmation mail. You need to confirm account creation by clicking on the confirmation link received in your inbox. Once, confirmation is complete, you will be redirected to Install Fabric screen and will be asked to choose your IDE. Choose Android Studio. Next, you will be asked to go through a list of tasks to integrate the Fabric plugin. You may also need to add organisation name. If asked, Add your organisation name.

Create New Project in Android Studio

Open Android Studio and take a new project as usual.

Install Fabric Plugin in Android Studio

To use Crashlytics in your project, you need to install Fabric plugin in your Android Studio as this is the easiest way to integrate Crashlytics kit. Follow the below steps for the plugin install.

  1. In Android Studio go to Android Studio > Preferences > Plugins.
  2. Click on “Browse Repositories”.
  3. Search for “Fabric” and install the plugins.
  4. Restart Android Studio for the plugins to take effect.
Install Fabric Plugins in Android Studio.

After restart complete, now you will find a new icon in the upper right of toolbar like below that is Fabric icon.

Fabric icon

Integrate Crashlytics in App

We have almost done. Integrating Crashlytics is quite simple.

  1. Click on Fabric icon to open fabric dialog.

2. Now Log in using your account credentials.

3. Once logged it will show organisations added in your account. Select an organisation for your app and click on Next button.

4. It will take you to the list of all the kits available in Fabric plugin. Select Crashlytics from the list.

5. It will take you to Install screen. Click on the Install button to install Crashlytics kit in your app.

6. During installation process, Fabric plugin will show you all the modification needed to be done to integrate Crashlytics kit and ask you to confirm it. To confirm, press on Next button.

Now plugin will start modifying app’s code. When all modifications are complete then it will ask you to run your application to complete the integration. Before run Sync your project.

7. Don’t forget to add INTERNET permission in Manifest.xml.

Once integration is complete, Crashlytics will start tracking all the crashes happening in the app without any extra code.

Force a test crash and check error reports in Crashlytics dashboard

To check whether the integration is working or not, we can add a force crash button and throw a RuntimeException in our application to force a crash.

Add a “Force Crash” button

Open your activity_main.xml file and paste this code into your layout where you’d like the button to appear. :

Throw a RuntimeException

Crashlytics will record any uncaught exception in your app. Throw a RuntimeException to your “Force Crash” button.

open MainActivity.java file and add the following code snippet to force for a crash.

Force a crash

Now, Run your application and tap the button. It will cause a crash. Now open your application again because Crashlytics sends crash reports to its server only after app is reopened.

In a minute or two you should be able to see the crash on your Crashlytics dashboard.

To check whether the crash is reported or not, open Fabric dashboard and select your app and you will be able to see to your Test Crash registered there. Below the graph are the crashes corresponding to certain lines of code. To view more detailed information about a crash, click an item on the list

Crash reports in Fabric dashboard

Not seeing the crash?

  • Make sure the Fabric.with() line is after all other 3rd-party SDKs that set an UncaughtExceptionHandler
  • Relaunch the app after it has crashed to retry uploading the crash

Don’t forget to take the forced crash out of your app before shipping!

Notice that in onCreate() we added a static method of Fabric

Fabric.with(this, new Crashlytics());

this is the one of the most important line. You must add it. Now the question, “If there is 20 Activities in my project. Should i use this line 20 times?” The answer is NO.

You can write this line just one time in your Application class and it will work for your entire application.

You must define this MyApplication class under name tag in Manifest.xml like below

android:name = ".MyApplication"

So the Manifest file will be like this

Some Extra Necessary things of Crashlytics may help you

User Informations with Crash Report

If you log user identifiers with the Crashlytics SDK while your app is running, Crashlytics will show them in crash reports on dashboard to help us for debugging.

User Information with Crash report in Crashlytics.

How many users are now using your app ???

To see how many users are currently using app you have to enable Runtime Analytics. To enable Runtime Analytics..

  1. Go to Fabric web dashboard.
  2. From left menu click on Retention or Growth.
  3. A popup message will open to enable Runtime analytics. So enable it.

After enabling Runtime Analytics just wait for a few minutes. You will see how many users are now using your app.

Enable Debugging

If you need to get a better look into what Fabric is doing behind the scenes, feel free to enable debug mode:

final Fabric fabric = new Fabric.Builder(this)
.kits(new Crashlytics())
.debuggable(true)
.build();
Fabric.with(fabric);

Want to log out from Fabric Plugin ?

Launch the Fabric plugin in Android studio. After loading it, hit Ctrl+L (Same command both in windows and mac) and It will make you log out. Yes, It is the worst user experience but there is no other way.

Some Other Crash Reporting Tools

  1. Raygan
  2. Firebase Crash Reporting (Google)
  3. Countly
  4. Instabug
  5. HockeyApp (Microsoft)

I hope you liked this article. Feel free to give your feedback in comment below. I would be very happy to get new suggestions.

Happy Coding :)

--

--

SHISHIR
PROGRAMMING LITE

{ 'designation' : 'Lead Software Engineer' , 'hobby' : [ 'Music', 'Photography', 'Travelling' ] ,’email’: ‘shishirthedev@gmail.com’ }