Monday, April 1, 2013

Adding Crash Reports

During the development phase of Android application you can use: Log messages, toast and debugger in order to debug your application.
You can use Android emulator or real device connected to your development environment in order to test your application and get all log messages and unexpected behavioral. 
While testing your application on real devices and especially after successful releasing the application it is very useful to get your application crash report. 
If your application crashes any where in the world it is better to know about it in order to fix it.
A free tool that enable the developer get his application crash report is ACRA
ACRA is very simple library that you add to your application.Crash reports are sent Google drive document and get email notification (please follow the setup steps).
The information receive from ACRA includes:

  • Application name and version
  • Phone brand and model
  • Android version and build number
  • Memory information
  • Device initial configuration
  • Crash configuration
  • Stack trace

More information can be add to the crash report for example logcat output, application log file etc...

Include ACRA in your application in four simple steps
1. Download ACRA library and include it in your application build path.
2. Add application class to the manifest and 
add internet permission. 

1:  <manifest ...>  
2:   <application ... android:name="MyApplication">  
3:    ...  
4:   </application>  
5:   <uses-permission android:name="android.permission.INTERNET">  
6:   </uses-permission>  
7:  </manifest>  

3. Generate Google Doc key (instructions from ACRA). Google drive document can be set to send  email notification on every change in the document. Remark Google has made changes in their Google forms for new option please see my post.

4. Implement application class
1:  import org.acra.*;  
2:  import org.acra.annotation.*;  
//Generate Google Doc code
3:  @ReportsCrashes(formKey = "dGVacG0ydVHnaNHjRjVTUTEtb3FPWGc6MQ")  
4:  public class MyApplication extends Application {  
5:   @Override  
6:   public void onCreate() {  
7:    // The following line triggers the initialization of ACRA  
8:    ACRA.init(this);  
9:    super.onCreate();  
10:   }  
11:  }       

ACRA report sender can be extend/change according to your application requirements by implementing you own report sender, example implementation for saving the crash report to file located on the SD card can be found here.