My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
ACRA3HowTo  
How to install ACRA 3.1 in your Android application.
Phase-Deploy, Deprecated
Updated Jul 1, 2011 by kevin.gaudin

This document is deprecated. It is related to ACRA v3.X which is not supported anymore. Please use ACRA v4.X.

Preamble

The main goal of this new version is to avoid the need of subclassing an ACRA-specific android Application class. This previous requirement was preventing developers to use both ACRA and other rich-featured libs/frameworks like GreenDroid, RoboGuice, Droid-Fu and others.

This goal has been achieved by moving the configuration of ACRA to a new ACRA-specific annotation @ReportsCrashes.

Introduction

ACRA allows your Android application to send Crash Reports in a Google Docs spreadsheet. This tutorial will guide you in installing ACRA in your application project.

Setting-up your project

Step by step installation of the ACRA library in an existing application project:

  • Get http://acra.googlecode.com/files/acra-3.1.2.2.zip and open the archive
  • Login to your Google Docs account
  • Import the CrashReports-template.csv contained in the archive (acra-3.1.2.2/CrashReport/doc), with conversion enabled
  • Open the imported document
  • Rename it as you like
  • In the menu, click on Forms / Create form
  • Add anything in the form description just to enable the Save button
    • If you are using a private Google Apps domain, make sure to uncheck the option "Require yourdomain.com sign-in to view this form."
  • Save the form
  • Copy the formkey displayed in the link at the bottom of the form creation page
  • Open your Eclipse project
  • Create a lib folder
  • Add the acra-3.1.2.2.jar from the archive (acra-3.1.2.2/CrashReport/build) in the lib folder
  • Right-click on the jar file / add to build path
  • Create a new class in your package root
    • Give it a name like: MyApplication, make it extend android.app.Application
    • Above the declaration of the MyApplication class, add the @ReportsCrashes annotation with your Google Docs form Id as a parameter

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

    @ReportsCrashes(formKey = "dGVacG0ydVHnaNHjRjVTUTEtb3FPWGc6MQ") 
    public class MyApplication extends Application {
    }
  • In the MyApplication class, override the onCreate() method to add the ACRA init statement
  •     @Override
        public void onCreate() {
        	// The following line triggers the initialization of ACRA
            ACRA.init(this);
            super.onCreate();
        }
  • Open the android manifest editor (AndroidManifest.xml
    • In the Application tab, click on the Browse button next to the Name field
    • Select your newly created Application class (MyApplication).
    This adds an android:name attribute to your application element like this (put the full name with package if the application class package is not the same as manifest root element declared pakage):
    <application android:icon="@drawable/icon" android:label="@string/app_name"
                    android:name="MyApplication">
    • In the Permissions tab, add a Uses Permission object with value android.permission.INTERNET.
    This adds the following element as a child of the manifest element:
    <uses-permission android:name="android.permission.INTERNET"></uses-permission>
  • THE END - next time your application crashes, it adds a line to your Google Docs spreadsheet :-).

Bonus : Google Docs spreadsheet allow to configure notifications on changes. Just set your preferences in : Share (Top right button) / Set notification rules and get notified by mail when reports are sent !

Spreadsheet default cells alignment is bottom left... select all cells and choose top left alignment:

Advanced Usage

User notification

The default behaviour of ACRA is to send crash reports silently. From the application user point of view, the application has crashed with the usual "Force Close" dialog, and that's all.

As a developer, you might prefer notifying your users that a crash report has been sent, or even ask him the authorization so send one... and why not ask him to describe what he was doing during the crash...

ACRA offers all these options, and allow you to customize your application crash reporting notifications.

2 main notification modes are available:

  • display a simple Toast with your developer designed text
  • display a status bar notification, then offering the user a dialog asking him to send the report or not, with an optional comment field you can chose to add or not.

Enabling user notification only requires you to add parameters to the @ReportsCrashes annotation :

  • Toast notification:
@ReportsCrashes(formKey="dGVacG0ydVHnaNHjRjVTUTEtb3FPWGc6MQ",
				mode = ReportingInteractionMode.TOAST,
				resToastText = R.string.crash_toast_text)
public class MyApplication extends Application {
...

In your strings.xml :

<string name="crash_toast_text">Ooooops ! I crashed, but a report has been sent to my developer to help him fix the issue !</string>
  • Status bar notification:
@ReportsCrashes(formKey="dGVacG0ydVHnaNHjRjVTUTEtb3FPWGc6MQ",
				mode = ReportingInteractionMode.NOTIFICATION,
				resNotifTickerText = R.string.crash_notif_ticker_text,
				resNotifTitle = R.string.crash_notif_title,
				resNotifText = R.string.crash_notif_text,
				resNotifIcon = android.R.drawable.stat_notify_error, // optional. default is a warning sign
				resDialogText = R.string.crash_dialog_text,
				resDialogIcon = android.R.drawable.ic_dialog_info, //optional. default is a warning sign
				resDialogTitle = R.string.crash_dialog_title, // optional. default is your application name
				resDialogCommentPrompt = R.string.crash_dialog_comment_prompt, // optional. when defined, adds a user text field input with this text resource as a label
                                resDialogOkToast = R.string.crash_dialog_ok_toast // optional. displays a Toast message when the user accepts to send a report.
				)
public class MyApplication extends Application {
...

In your strings.xml:

<string name="crash_notif_ticker_text">Unexpected error, please send a report...</string>
<string name="crash_notif_title">CrashTest has crashed...</string>
<string name="crash_notif_text">Please click here to help fix the issue.</string>
	
<string name="crash_dialog_title">CrashTest has crashed</string>
<string name="crash_dialog_text">An unexpected error occurred forcing the
	application to stop. Please help us fix this by sending us error data,
	all you have to do is click \'OK\'.</string>
<string name="crash_dialog_comment_prompt">You might add your comments about the problem below:</string>
<string name="crash_dialog_ok_toast">Thank you !</string>

In your AndroidManifest.xml

<application ...>

    ....

    <activity android:name="org.acra.CrashReportDialog"
        android:theme="@android:style/Theme.Dialog"
        android:launchMode="singleInstance"
        android:excludeFromRecents="true"
        android:finishOnTaskLaunch="true" />

    ....

</application>

May I send reports to my own php/java/python/whateveryouwant self-hosted script ?

Just use the formUri parameter of the @ReportsCrashes annotation in your Application class :

@ReportsCrashes(formKey="", // will not be used
				formUri="http://yourserver.com/yourscript",
				mode = ReportingInteractionMode.TOAST,
				resToastText = R.string.crash_toast_text)
public class MyApplication extends Application {
...

Then your script has to follow the fields mapping exposed in the ErrorReporter class.

Can I add my own variables content in the crash report ?

Absolutely !

Simply use the following method in key places in your code :

ErrorReporter.getInstance().putCustomData("myVariable", myVariable);

All your custom data (only latest value for each one) will be added in the column "custom" just before the stack trace, one key = value pair per line.

You can also use getCustomData("myVariable") and removeCustomData("myVariable") to get/remove data from the custom data map.

Can I let the user disable error reporting ?

Yes, you can !

All you have to do is add to your preferences xml file a CheckBoxPreference :

<CheckBoxPreference android:key="acra.disable"
	android:title="@string/pref_disable_acra"
	android:summaryOn="@string/pref_acra_disabled"
	android:summaryOff="@string/pref_acra_enabled"
	android:defaultValue="false"/>

Or if you prefer to allow your user to check the box to enable reporting:

<CheckBoxPreference android:key="acra.enable"
	android:title="@string/pref_disable_acra"
	android:summaryOn="@string/pref_acra_enabled"
	android:summaryOff="@string/pref_acra_disabled"
	android:defaultValue="true"/>

Then add to your strings.xml files the 3 corresponding string resources.

If your SharedPreferences are not the application default SharedPreferences, you can provide ACRA with your own SharedPreferences name using the following @ReportsCrashes parameters:

  • sharedPreferencesName: Name of the SharedPreferences that will host the acra.enable or acra.disable preference.
  • sharedPreferencesMode: The mode that you need for the SharedPreference file creation: Context.MODE_PRIVATE, Context.MODE_WORLD_READABLE or Context.MODE_WORLD_WRITEABLE.

Can I send reports for caught exceptions ? or for unexpected application state without any exception ?

As a good programmer, your code is full of try/catch statements, and sometimes an interesting (unexpected) exception might be caught in one of these.

You could also want your application to send a report without any Exception thrown, just because you know that your application is in an unexpected state.

Both of these needs can be covered by this :

ErrorReporter.getInstance().handleException(caughtException);

You can provide any caught or custom Exception, or even null if you don't have any to provide.

If you need to add silent trace reports whatever notification mode you configured for your application, you can also use:

ErrorReporter.getInstance().handleSilentException(caughtException);
Comment by gyetvan....@gmail.com, Dec 5, 2010

I'm just tested and it works perfectly. It is included from now in my beta to report crashes (hope that Google Doc remains near empty :-) ) Thanks a lot !

Comment by KinkyMun...@gmail.com, Dec 13, 2010

Does not work if the crash occurs in native code.

Comment by project member kevin.gaudin, Dec 13, 2010

@KinkyMunkey?> I have never used NDK. Did ACRA v2 work with native code crashes ?

Comment by gordo...@gmail.com, Dec 14, 2010

Everything works using the NOTIFICATION mode except that I wasn't seeing the toast message. Then I realized that in your documentation above you left out what I assume should be resDialogOkToast, correct?

Comment by project member kevin.gaudin, Dec 14, 2010

@gordonwd> you're right! I just updated the doc to fix this. Thanks!

Comment by KinkyMun...@gmail.com, Dec 15, 2010

I didn't try acra2, Not sure how you would go about trapping them- they print out a stack trace in the "DEBUG" level logs - and the application just stops.

This is not limited to NDK apps - I also had a libSkia.so crash in the core android libraries that also did not send a bug report (that was related to null pointer-memory issues w/ loading a png file - but the crash occurred in the native android code and spit out a stack trace)

these are SIGs as opposed to traditional java crashes- SIGSEV and SIGILL are the two I experienced (SIGILL is a bad instruction - i.e. using NEON instructions on a phone that does not support the ARM/NEON instruction set, SIGSEV is the aforementioned memory issues)

you can NOT try/catch SIGS either...

Comment by KinkyMun...@gmail.com, Dec 15, 2010

BTW, great work, thanks :-) saved me a bunch of time.

Comment by project member kevin.gaudin, Dec 16, 2010

Ok, I don't think we can do anything to catch native crashes if they don't result in a Java Exception.

In a future release, I'm planning to add an option to (optionaly) upload a short logcat extract + DropBoxManager? system items. This should allow to get some of these traces, but only if an exception triggers the report... or if you detect an unexpected state and trigger a report yourself.

Comment by gordo...@gmail.com, Dec 18, 2010

My users are generally not too techie (average age 40+), so I'm afraid with mode NOTIFICATION they might be confused by the app suddenly just disappearing and then miss the notification, and with TOAST the toast message might not be noticed (text is kinda small, too). What I'd like is a combo, where CrashReportDialog? comes up immediately when the app crashes, similar to the default Force Close dialog. Any way to do this now?

Comment by project member kevin.gaudin, Dec 19, 2010

@gordonwd> This is what we would have implemented first if it was possible. Unfortunately, when an uncaught exception goes up to the UncaughtExceptionHandler?, the process seems to be put in a state which prevents it from starting new activities (and the dialog is one).

We are investigating some workarounds but they are complex to implement and require, from the moment, too much modifications on the application lifecycle.

If we ever find a usable solution, we will provide it.

Comment by pujos.mi...@gmail.com, Dec 23, 2010

Thanks for ACRA. I'm using it since a few month to monitor crashes in a beta app (in automatic mode) and it's been a real life saver to catch odd crashes.

A suggestion: when a OutOfMemory? exception happens, it would be nice to include and estimate of the RAM used by the app at that time, and the memory limit for an app on that particular device for which the dalvik VM won't allocate more memory (if doable).

Comment by JohnLuss...@gmail.com, Dec 29, 2010

I'm trying out ACRA, and have one question. What does the Google Doc template Visibility have to be set to?

Comment by project member kevin.gaudin, Dec 29, 2010

@pujos.michael: I'll try to include more data about application process memory status in v3.2.

@JohnLussmyer?: The visibility setting does not matter, you may want to change it only if you want to share the spreadsheet with other people.

Comment by JohnLuss...@gmail.com, Dec 30, 2010

Except that when visibility was Private, the report didn't seem to work.

Comment by project member kevin.gaudin, Dec 31, 2010

@JohnLussmyer?> Strange, all my spreadsheets are private, it works.

Comment by JohnLuss...@gmail.com, Dec 31, 2010

Yeah, it started working for me as well. Who knows, maybe it was just a network hiccup. I have noticed during Development that the app sometimes crashes without sending a report or notifying the user - and then when Eclipse reloads the Emulator with the app - it THEN puts up the crash notification box.

Comment by testexpe...@gmail.com, Jan 10, 2011

Thanks for this great tool. For me the reports are not written into the google spreadsheat until the user restarts the app. Maybe that was the same issue with JohnLussmyer??

Greetings from Lucerne Stephan Wiesner

Comment by testexpe...@gmail.com, Jan 10, 2011

Seems to me that the report is send every time the crash occures - except for the first time! On first run a crash report file is written, but not send to spreadsheet?

Comment by chris.fo...@gmail.com, Jan 11, 2011

this works great, many thanks for all your work.

Comment by testexpe...@gmail.com, Jan 12, 2011

If there is a crash and the report is not send and the user restarts the app, acra again displays an error message - even if there is none now...

Stephan Wiesner

Comment by martin.h...@gmail.com, Jan 14, 2011

I don't know if this is an error or not, so I didn't open an issue:

ErrorReporter?.getInstance().putCustomData("a"); ErrorReporter?.getInstance().handleSilentException(null);

A report with "a" is generated.

ErrorReporter?.getInstance().putCustomData("b"); ErrorReporter?.getInstance().handleSilentException(null);

A report with "b" AND with "a" is generated. If I only want "b", I have to do

ErrorReporter?.getInstance().removeCustomData("a");

I assumed that handleSilentException would clean out all custom data since it is sent now.

Comment by tograd...@gmail.com, Jan 24, 2011

Thank you so much for making this, it has been incredibly helpful.

You are a saint!

Comment by Boris...@gmail.com, Jan 30, 2011

Kevin, what an impressive effort! joining others - please put donation link so we can thank you and buy your a beer!

one question for you, I want to add my code if error happens to free up some resources (wake lock and keyguard), can I do that and how?

Thank you!

Comment by Boris...@gmail.com, Jan 30, 2011

one more question...I've got reports from my test app and I can see them in google docs, but the only field filled is stack one - the rest are blank. Do you know why?

Comment by Boris...@gmail.com, Jan 30, 2011

or sorry, no, they are not blank, just not shown for some reason. if a click on a cell, I can see the content.

Comment by jaulo...@gmail.com, Jan 31, 2011

What about offline crashes?

Ex.: I'm using an online app (all data are in the cloud) but a connection loss causes a crash. As ACRA uses the same connection to send errors, these crashes will be lost. Could these errors be saved in files permanently or to be sent later? Android Error Reporter (https://github.com/tomquist/Android-Error-Reporter) defines a good strategy to this.

Is there some expectation to treat these situations?

I'm searchingo for a crash report and ACRA is the best until now but it can be excluded because this gap...

Thanks in advance.

Comment by project member kevin.gaudin, Jan 31, 2011

@Boris> As explained by mail, there will be some pluggable custom code possible in ACRA 3.2. But this is called either on crash time or after an application restart. Though, as apps are killed and restarded after a crash there should be no need to release anything. If other needs of hooks appear we will implement them in a further release.

About the data not appearing in the spreadsheet cells, I'll add a paragraph in the doc about configuring the spreadsheet to align it's data on top left instead of the default (weird) bottom left. There's a button for this in the toolbar (it took me months to find it too ;-)

@jaulo> Even if it is not explained in the doc, ACRA supports resending unsent reports since the earliest version. If this does not work for you please file an issue in the issue tracker.

Comment by project member kevin.gaudin, Jan 31, 2011

MESSAGE TO EVERYONE:

I created a Google Group for discussions about acra: https://groups.google.com/group/acra-discuss

This should be a good place for both support and discussions about next features to be implemented.

Comment by jaulo...@gmail.com, Feb 1, 2011

Thanks kevin.gaudin! I've not tested properly. It really works offline.

Thanks and good job!

Comment by t...@teknogrebo.co.uk, Feb 11, 2011

@Boris, that caught me as well for a moment. The template is formatted so that all cells are bottom justified. The data is there (as you saw), it's just that stacktrace makes rows incredibly high :)

Btw - Just added Acra support to my app. Hopefully it will prove to be useful :)

Comment by project member kevin.gaudin, Feb 12, 2011

I will add a few tips to configure the layout in the spreadsheet to get rid of the default 'align to bottom' behavior.... it's simple but it took me months to find out...

Comment by nex_otaku@mail.ru, Feb 23, 2011

Kevin, there is a missed step in "Setting-up your project" section. Developer must add following lines to an application class:

import org.acra.*;
import org.acra.annotation.*;
Comment by project member kevin.gaudin, Feb 23, 2011

Added. Thanks ;-) (I was assuming that the IDE adds needed imports almost automatically. But you're right, it's better to list write them here.)

Comment by swex...@gmail.com, Mar 2, 2011

Kevin, can you let us know those tips to configure the layout? It would be really helpful. Thanks!

Comment by project member kevin.gaudin, Mar 2, 2011

I already added all I know... which fits in this picture:

Comment by aliasgha...@gmail.com, Mar 14, 2011

kevin i am getting the following error

java.io.FileNotFoundException?: http://spreadsheets.google.com/formResponse?formkey=dGVacG0ydVHnaNHjRjVTUTEtb3FPWGc6MQ&amp;ifq

if i copy paste the URL into browser i am unable to find the document. but when i remove amp; from &amp;ifq then the link works. Could you let me know if i am doing something wrong from my end or is this an issue.

Comment by grischa....@gmail.com, Mar 15, 2011

Wow! This library is so good and helpful, can't believe it! Thanks a lot!

Works inside of my application without any problems yet.

I only have one wish: I would like to have a combination of the notification and toast mode. I think, the notification mode is perfect, but some users might not notice that there was a crash (or to late for knowing, where it was produced). A toast aside of the notification informing about the crash would make this more visible.

But: Thanks a lot!

Comment by project member kevin.gaudin, Mar 15, 2011

The TOAST + NOTIFICATION will be possible in v3.2.0. Actually I added this feature because there could be some time (~2 or 3 seconds) between the crash and the notification due to data collection, so there is a need to give some feedback to the user right on crash time. ETA... as soon as I find the time to test and update the documentation.

To aliasgha...@gmail.com> please post to http://groups.google.com/group/acra-discuss or open an issue, this comments page is not the better tool for support ;-)

Comment by testexpe...@gmail.com, Apr 6, 2011

Hi, I have the user notification enabled. If there is a crash, the notification will come every time the app is started, until the message is send. The user often does not see the notification/does not react to it and gets a crash message on each start. This looks to him as if my app crashed each time :-( Anyway around this problem? Without a workaround I will have to remove acra from my project whicht would be a real shame :-(

Thanks, Stephan

Comment by mrpratee...@gmail.com, Apr 8, 2011

Great work !!

Comment by vasanth....@gmail.com, Apr 11, 2011

Amazing work! Incredibly useful!

Comment by chbrigh...@gmail.com, May 10, 2011

I'm missing something: I don't see how providing the formkey for a skeleton form allows the API to access/update the imported spreadsheet from CrashReports?-template.csv?

Comment by chbrigh...@gmail.com, May 18, 2011

Resolved my error. I want back to the main page and took the "Create New" to make the Form. Should have stayed in the imported spreadsheet and taken the Tools->Form->"Create a form" path to make the entry form.

Comment by beargrea...@gmail.com, Jun 1, 2011

Fantastic and works like a charm. Thanks for the helpful instructions on how to use.

Comment by ola...@pitechnologies.ro, Jun 2, 2011

Great !!!

Comment by prav...@thenextpointer.com, Mar 17, 2012

hi for my app it prompt me that UnknownHostException?: ,please help me

03-17 22:26:52.049: ERROR/ACRA(304): Failed to send crash report for 1332001447000-approved.stacktrace

org.acra.sender.ReportSenderException?: Error while sending report to Google Form. at org.acra.sender.GoogleFormSender?.send(GoogleFormSender?.java:64) at org.acra.ErrorReporter?.sendCrashReport(ErrorReporter?.java:850) at org.acra.ErrorReporter?.checkAndSendReports(ErrorReporter?.java:960) at org.acra.ErrorReporter?$ReportsSenderWorker?.run(ErrorReporter?.java:142) Caused by: java.net.UnknownHostException?: spreadsheets.google.com at java.net.InetAddress?.lookupHostByName(InetAddress?.java:513) at java.net.InetAddress?.getAllByNameImpl(InetAddress?.java:278) at java.net.InetAddress?.getAllByName(InetAddress?.java:242) at org.apache.http.impl.conn.DefaultClientConnectionOperator?.openConnection(DefaultClientConnectionOperator?.java:136) at org.apache.http.impl.conn.AbstractPoolEntry?.open(AbstractPoolEntry?.java:164) at org.apache.http.impl.conn.AbstractPooledConnAdapter?.open(AbstractPooledConnAdapter?.java:119) at org.apache.http.impl.client.DefaultRequestDirector?.execute(DefaultRequestDirector?.java:348) at org.apache.http.impl.client.AbstractHttpClient?.execute(AbstractHttpClient?.java:555) at org.apache.http.impl.client.AbstractHttpClient?.execute(AbstractHttpClient?.java:487) at org.acra.util.HttpRequest?.sendPost(HttpRequest?.java:109) at org.acra.util.HttpRequest?.sendPost(HttpRequest?.java:80) at org.acra.util.HttpUtils?.doPost(HttpUtils?.java:59) at org.acra.sender.GoogleFormSender?.send(GoogleFormSender?.java:62) ... 3 more


Sign in to add a comment
Powered by Google Project Hosting