android_bugs_acra
Programmer's notes

ACRA for Android

0 15

When writing applications for smartphones there will be a time that you will have to deal with production errors. You should do whatever it takes to eliminate errors from your app before releasing it to production. You should do unit, integration, regression, end to end testing for every release. But there is no such thing as an 100% error free application. There are some errors for sure, you are just not aware of them yet. And no matter how long and good you are testing you app, there is some chance that your application will crash leaving user with unpleasant feeling. And the way you’re dealing with those kind of situation shows how good of a developer are you.

First, you should show your users information that this situation is rare and all the details were collected for analyzing and improving your application. Second, you should be able to gather all the details of an error: application version, phone model, system version and the most important the stack trace when crash happened.

Fortunately there are many libraries and solutions that can do it for you. One of them, for Android ecosystem, and the one that I am using is the library called ACRA (they have very good documentation and community behind it – https://github.com/ACRA/acra). It is very easy to use and deals with all aspects of error collection. It can be applied to your app in just a few minutes. And this is the very basic setup, the simplest one.

You have to do two things:

  1. Configure your Android application to send error reports to you
  2. Create backend to where the errors will be send

The configuration and launching should be done on the Main Application class. This is for example my configuration of ACRA library:

I am setting the default behaviour mode (what to do when the crash happens) on line 5 to display simple Toast with appropriate text from string resources. And don’t forget to start ACRA (line 15) :)

There are many ways you could configure ACRA. The behaviour mode: from not showing anything to ask user for comments. The backend: from email to your own report sender. You can even allow user to configure it. For all possible scenarios, please read ACRA github pages.

The endpoint, where I am collecting errors has a very basic PHP script to save all sended POST fields into a file. One file per error report:

And that’s all. This is the basic setup that allows you to start receiving (yes, you will be receiving) production errors from your Android application. Now you are ready to analyze ACRA error reports.

Have fun and take care of your users.

C.

Leave a Reply

DEV

Around Dev

My way of seeing

%d bloggers like this: