Back to Blog Home

Mobile Crash Reporting: Helpful Tips on How to Investigate Mobile Crashes

Nabendu Biswas image

Nabendu Biswas -

Mobile Crash Reporting: Helpful Tips on How to Investigate Mobile Crashes

A mobile application can crash for a variety of reasons, and it is sometimes difficult to know the reason. Android mobile crashes cause more problems because of the huge number of Android mobiles and the different OS they run. In this post, we will generate a simple error and then look at multiple ways to monitor the error.

We’ll check the crash reporting through the log available in Android Studio. Then, we’ll compare Crashlytics and Sentry to see how each tool investigates errors and mobile crashes.

Initial Setup

We will first create a simple app for our post that we will use with Android Studio, Crashlytics, an Sentry.

First, we will create a new project in Android Studio. After opening Android Studio, click on New -> New Project.

mobile-crash-reporting-image10

On the next screen, click on Empty Activity and then the Next button.

mobile-crash-reporting-image12

You’ll be asked to give the Name and Language. Give any name, but choose Java for the language because we are going to write a small app in Java.

mobile-crash-reporting-image11

After that, the activity_main.xml will open. Here, click on Split to open the code.

mobile-crash-reporting-image14

Now we are going to change the code a bit and add a MaterialButton. We’ll also add text and id to it.

mobile-crash-reporting-image13

Next, open the MainActivity.java file and add a new in-built function, findViewById. Here, we are taking the id of crash and hence selecting the button. After that we are adding a new click listener. Here, we are just throwing an exception.

mobile-crash-reporting-image15

Logcat Crash Reporting

We will first look into checking the crash reporting by using Android Studio. Logcat is a good feature that will help us investigate the mobile crashes.

We will first start our Android app on the emulator, as shown below. Here, click on the Crash App button.

mobile-crash-reporting-image2

Now, go back to Android Studio and click on Logcat at the bottom. It will open a tab showing our error. The error is shown correctly, but there isn’t much information about it.

mobile-crash-reporting-image19

Challenges with Mobile Crash Reporting

We have a lot of challenges with mobile crash reporting with in-built tolls like Logcat. As mentioned above, there isn’t much information. That’s fine for this small app, but for a larger production app it’s a bigger problem.

Second, it is very difficult to find the root cause of the error, even in our small app.

But the biggest problem is when the mobile app is deployed on the Google Play Store. Android is fragmented, with thousands of different models, and a lot of mobiles are not updated with the latest Android OS. Generally the developer develops the mobile app in the latest Android OS and the testers test them on a limited number of devices running different OS.

So, when an app fails on an old mobile device running an old Android OS, it is very hard to reproduce. Google provides crash reports for deployed apps, but it is very difficult to continuously monitor and get the error data.

Crashlytics for Mobile Crash Reporting

Let’s first look at Crashlytics, Google’s cloud based crash reporting tool. It solves most of the problems with Logcat and other built-in tools. This tool is from Google’s Firebase Suite, so you need to have an account to use it.

We can create a new app in Firebase or add an existing app. We are going to do the latter. To accomplish that, after opening our existing app, click on + Add app.

mobile-crash-reporting-image17

A menu will open showing different types of apps. Click on the Android app icon.

mobile-crash-reporting-image24

Next, we need to register the app. Here, in the Android package name, give the exact name of the Android app created earlier. Then click on the Register app button.

mobile-crash-reporting-image20

Click on Download google-services.json and it will download the file. Then click on the Next button.

mobile-crash-reporting-image22

Now it will give us instructions to add dependencies in build.gradle files. Scroll down and click on the Next button.

mobile-crash-reporting-image25

Go into the root build.gradle file in Android Studio and add the dependencies.

mobile-crash-reporting-image27

We also need to add dependencies in the module build.gradle file in Android Studio.

mobile-crash-reporting-image29

Back in Firebase, click Continue to get to the console button.

mobile-crash-reporting-image31

According to official Firebase Crashlytics documentation, we need to add some more dependencies and plugins in the module build.gradle file.

mobile-crash-reporting-image33

We also need to add more dependencies in the root build.gradle file as shown below.

mobile-crash-reporting-image35

Next, the downloaded google-services.json file needs to be added in the app folder.

mobile-crash-reporting-image36

The project will ask us to sync. Click on the Sync Now link on the top right corner.

mobile-crash-reporting-image37

Now, in the Firebase Console, go to Release and monitor and then click on Crashlytics. Here, you will see that the app has been detected and is waiting for a crash.

mobile-crash-reporting-image1

Restart the app and click on the Crash App button.

mobile-crash-reporting-image2

Firebase will show us the error with a lot of other metrics. Click on the displayed error.

mobile-crash-reporting-image3

Here, we will see details of the error and other meta data. We see the connected phone model number, which in our case is an emulator. And we also see the time at which the error was generated.

The operating system on which we got the error is also shown (in our case it is Android Version 13). This is particularly useful, as older versions of Android run on a lot of phones. And sometimes, we get errors on those phones.

We also get a nice graph showing the number of errors, which is low in our example app. In the case of more scaled production apps, it will be much higher.

mobile-crash-reporting-image4

As we have seen in the last two screenshots, Crashlytics provides a lot of metrics, from the number of crashes and the number of users, phone model, OS version, the specific device name (with details and logs), and more.

mobile-crash-reporting-image6

mobile-crash-reporting-image7

What’s more, Firebase will continuously monitor our application, including the deployed production app in the Google Play Store.

Mobile Crash Reporting using Sentry

Now let’s look into another cloud-based tool for mobile app crash reporting: Sentry. Sentry’s setup was very straight-forward and less involved compared to Crashlytics.

After you create a Sentry account, you’ll be on your way to setup. Sentry supports nearly every major language and framework. We’ll want to setup an Android project.

mobile-crash-reporting-image8 mobile-crash-reporting-image9

Next, we’ll get instructions to add dependencies in our application.

mobile-crash-reporting-image16

Back in the module build.gradle file in Android Studio, we need to add a plugin for Sentry.

mobile-crash-reporting-image18

We’ll also add the implementation and compileOptions in the build.grade file.

mobile-crash-reporting-image21

Now, we’ll add the meta data containing our keys from Sentry docs in the AndroidManifest.xml file.

mobile-crash-reporting-image23

Finally, we will refactor our code in the MainActivity.java file. Here, we are importing Sentry and using it in a try…catch block.

mobile-crash-reporting-image26

Jumping into Sentry, we’ll see errors in our Android Project.

mobile-crash-reporting-image28

In the Issues tab, we can see our error.

mobile-crash-reporting-image30

Here, we have a lot of options to track the error (for example, we can resolve or ignore it or mark it reviewed). Again, we are getting all the details and meta data of the device and the environments, and we can also assign this error to someone on our team to fix with the available integrations to GitHub and/or Jira.

mobile-crash-reporting-image32

We are getting a lot more details in the log, which can help us solve the error more easily. As you can see from the screenshots, Sentry provides us with both Breadcrumbs and Stack Traces for each of the issues reported.

Breadcrumbs tell us how the user got to the point when the issue occurred. We can use that info to reproduce the crash locally, which makes it much easier to fix the issue.

Stack Traces on the other hand give us the execution flow of the functions and methods that lead up to the crash. Function A called function B, which called function C and then the app crashed. We’d know where those three functions are within our codebase. Using this info, we can look into how those three functions are connected to each other, and figure out what caused the crash.

mobile-crash-reporting-image34

Challenges Solved With Sentry

As we have seen in the past three screenshots, Sentry is an advanced cloud-based tool with far more advanced crash-reporting features, such as:

  • Breadcrumbs
  • Stack Traces
  • Device Info
  • Profiling
  • User Feedback
  • Alerts

Sentry also has a lot of integrations, like issue-tracking with Jira, which allows us to track and assign bugs to different developers on our team.

Recap

In this post, we learned about mobile crash reporting. We created a simple Android app to crash. We first learned to check logs in the built-in Logcat in Android Studio. Here, we saw many challenges in crash reporting.

We checked out two cloud-based crash-reporting tools: Crashlytics and Sentry. Sentry has more features and felt much easier to use. You can get started with both tools for free.

Share

Share on Twitter
Share on Facebook
Share on HackerNews
Share on LinkedIn

Published

Sentry Sign Up CTA

Code breaks, fix it faster

Sign up for Sentry and monitor your application in minutes.

Try Sentry Free

Topics

Guest Posts

The best way to debug slow web pages

Listen to the Syntax Podcast

Of course we sponsor a developer podcast. Check it out on your favorite listening platform.

Listen To Syntax
    TwitterGitHubDribbbleLinkedinDiscord
© 2024 • Sentry is a registered Trademark
of Functional Software, Inc.