Crash reporting is a pretty important part of any successful project, so this week I thought I would write a little bit about implementing Crashlytics on Android. The Fabric documentation itself is pretty good but I didn’t find a whole lot of other articles about it online.

Why should you implement Crashlytics?

It’s really up to you, you might not need to add it straight away to a new project but I usually do. Aside from Android Vitals(which doesn’t actually send you emails or notifications) it’s pretty difficult to figure out if you are getting crashes in your app. Some users might be nice(haha) enough to leave you a one star review telling you your app isn’t working in some capacity. Usually they won’t give you a lot of details though, so you’ll know you have an issue but won’t know where.

Crashlytics helps you out with this, you will be able to see errors for each version of your app in the dashboard. It will also send you emails if it detects new issues that are causing a large percentage of session crashes. This has been invaluable for me, especially when I add new features to something and end up accidentally shooting myself in the foot. No one is perfect, but if you have something to pinpoint where the error is occurring it is much easier to ship out a fix.

You might also like to activate Answers with Crashlytics, Answers is another feature of Fabric that shows you analytics data like DAU/MAU or app retention. This is less useful but it’s still good to know how many users you’re getting a day and how many of them are first timers. You can also record event data so it can help with optimizing funnels and what not.

Is Crashlytics perfect?

No, of course not. Is anything perfect? Sometimes I get issues on Android Vitals I don’t see on Crashlytics and vice-versa. I would monitor both to get a clear idea of whether you’re have any serious problems. That being said Crashlytics works very well and it is free. Fabric was also acquired by Google last year so things should only keep getting better.

Implementing Crashlytics

The process is pretty straight forward. First you need to actually sign up for Fabric. If you want you can install a gradle plugin to guide you through the whole process, it’s nice but kind of sluggish sometimes so I just prefer to install manually. First you need to make some changes to your project-level build.gradle. Add a build script node at the top(you could alternatively add this to your top-level build.gradle):

Then you need to apply the fabric plugin, you can add this below “apply plugin: ‘'”:

After that make sure you add this to your repositories node:

Then you just need to add the library to your dependencies:

After that you need to add your API key to your AndroidManifest.xml file, make sure it’s inside the <application> tags:

Also make sure you’ve declared the Internet permission in your manifest file:

The last thing you need to do is initialize Fabric, they recommend you do this in your MainActivity. Here’s what doing so would look like in Kotlin:

After that’s done you just need to build and run your project. Shortly after you should get an email from Fabric telling you a new property has been added to your account(including the package name).

What about Answers

You don’t need to add any extra code for Answers, but Fabric won’t automatically activate it for you. You have to go into your dashboard, select your app and then click on something other than Crashlytics, like ‘Growth’ or ‘Engagement’.

Crashlytics dashboard

Other options

Then you’ll get a dialogue asking if you want to activate Answers with a picture of a rocket. You confirm and then it asks you do a fresh install of your app. This is the part I hate the most because it’s very finicky. Sometimes I’ve uninstalled and re-installed an app 3 or 4 times before it actually registers, and it also has a time-out. If you’re having issues with this you’re not alone, it might also help to switch your initialization method so debug mode is turned on temporarily. Then you will get some details in your logcat about what is happening. Here’s an example:

Wrap Up

And that’s pretty much all there is to it. Adding Fabric to a project is actually pretty painless compared to some other frameworks. If you have anything to add feel free to comment. Last year I wrote another post about screen pinning on Android, if that’s something you’re interested in you can read about it here. Otherwise, have a great weekend.