Coming Up for Air

Error Reporting for Android Apps

Friday, April 05, 2013 |

As every Android developer knows, application crashes are reported back to Google and can be view in the Play Developer’s Console. This is helpful, but, in my experience, sometimes you don’t get enough context. You also don’t get notifications when crashes are reported. Fortunately, there is a tool, called ACRA, that improves the situation quite a bit. In this post, I’ll give you a brief introduction to the tool, and how I use it in Cub Tracker.

If you look at the ACRA home page, the quick start suggests a code snippet like this:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
import org.acra.*;
import org.acra.annotation.*;

@ReportsCrashes(formKey = "dGVacG0ydVHnaNHjRjVTUTEtb3FPWGc6MQ")
public class MyApplication extends Application {
  @Override
  public void onCreate() {
    // The following line triggers the initialization of ACRA
    super.onCreate();
    ACRA.init(this);
  }
}

In a nutshell, this configuration will tell ACRA to report all crashes to a Google Docs form. While helpful, I’ve found this less than optimal, as the spreadsheet the form feeds gets very hard to read. Then, there’s this, also from the ACRA home page:

Since the recent update of Google Forms by Google, the usage of Google Docs as a storage engine for ACRA reports is becoming deprecated.

— http://acra.ch/

So my advice is to skip it. :) What I’ve done in Cub Tracker is to configure an HttpPostSender instance:

1
2
ACRA.init(this);
ACRA.getErrorReporter().setReportSender(new HttpPostSender(ERROR_REPORTING_URL, null));

Now, rather than posting to a Google Form, it POSTS to my custom web service, which looks like this (please excuse the ugly PHP :) :

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
<?php
$message .= "PHONE_MODEL = " . $_POST["PHONE_MODEL"] . "\n";
$message .= "ANDROID_VERSION = " . $_POST["ANDROID_VERSION"] . "\n";
$message .= "PRODUCT = " . $_POST["PRODUCT"] . "\n";
$message .= "APP_VERSION_CODE = " . $_POST["APP_VERSION_CODE"] . "\n";
$message .= "APP_VERSION_NAME = " . $_POST["APP_VERSION_NAME"] . "\n";
$message .= "STACK_TRACE:\n" . $_POST["STACK_TRACE"] . "\n";

// Send
mail('me@foo.com', 'Cub Tracker Error Report', $message);

?>

That results in an email like this:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
PHONE_MODEL = Galaxy Nexus
ANDROID_VERSION = 4.2.2
PRODUCT = mysid
APP_VERSION_CODE = 19
APP_VERSION_NAME = 2.3
STACK_TRACE:
java.lang.IllegalStateException: Couldn't read row 0, col 0 from CursorWindow.  Make sure the Cursor is initialized correctly before accessing data from it.
	at android.database.CursorWindow.nativeGetLong(Native Method)
	at android.database.CursorWindow.getLong(CursorWindow.java:507)
	at android.database.AbstractWindowedCursor.getLong(AbstractWindowedCursor.java:75)
...

That nicely demonstrates the flexibility of ACRA, as well as one the most frustrating and elusive bugs in my app, but, hopefully, my pain can help you with your app. :)

Search

    Quotes

    Sample quote

    Quote source

    About

    My name is Jason Lee. I am a software developer living in the middle of Oklahoma. I’ve been a professional developer since 1997, using a variety of languages, including Java, Javascript, PHP, Python, Delphi, and even a bit of C#. I currently work for Red Hat on the WildFly/EAP team, where, among other things, I maintain integrations for some MicroProfile specs, OpenTelemetry, Micrometer, Jakarta Faces, and Bean Validation. (Full resume here. LinkedIn profile)

    I am the president of the Oklahoma City JUG, and an occasional speaker at the JUG and a variety of technical conferences.

    On the personal side, I’m active in my church, and enjoy bass guitar, running, fishing, and a variety of martial arts. I’m also married to a beautiful woman, and have two boys, who, thankfully, look like their mother.

    My Links

    Publications