Coming Up for Air

Error Reporting for Android Apps

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:

import org.acra.*;
import org.acra.annotation.*;

@ReportsCrashes(formKey = "dGVacG0ydVHnaNHjRjVTUTEtb3FPWGc6MQ")
public class MyApplication extends Application {
  public void onCreate() {
    // The following line triggers the initialization of ACRA

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.


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

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 :) :

$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('[email protected]', 'Cub Tracker Error Report', $message);


That results in an email like this:

PHONE_MODEL = Galaxy Nexus
PRODUCT = mysid
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(
	at android.database.AbstractWindowedCursor.getLong(

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. :)

tags: Android


Sample quote

Quote source