[Android] Using Crittercism for Real-time Crash Report Monitoring

Tadashi Shigeoka ·  Thu, July 4, 2013

I introduced a service called “Crittercism” to an Android app for real-time crash report monitoring.

Crittercism | Mobile Application Performance Management

The free version is quite useful and has been very helpful.

This time, I’ve added my own research notes to the content written in the official documentation.

Crittercism - Installation Instructions

Below is a memo of the actual code I’m using.

AndroidManifest.xml


I didn’t grant READ_LOGS permission since more than half of users were using Android 4.1 or higher devices.

About Android 4.1 and above operation: On devices with Android 4.1 (Jelly Bean) and above, remote LogCat functions even without this setting. However, for security reasons, only logs output from the app's own process can be referenced.

[Quote from]: リモートLogCatの有効化 - DeployGate

MainActivity.java

The initCrittercism method is called from the onCreate method.

import com.crittercism.app.Crittercism;

/**
 * Initialize Crittercism (Error reporting and monitoring tool.)
 * http://www.crittercism.com
 */
private void initCrittercism() {
    JSONObject crittercismConfig = new JSONObject();
    try {
        // include version code in version name
        crittercismConfig.put("includeVersionCode", true);
        // necessary for collecting logcat data on Android Jelly Bean devices.
        crittercismConfig.put("shouldCollectLogcat", true);
    } catch (JSONException je) {
    }

    Crittercism.init(getApplicationContext(), "", crittercismConfig);
}

proguard.cfg

If using proguard, add the following settings as well.

-keep public class com.crittercism.**

-keepclassmembers public class com.crittercism.*
{
    *;
}

Finally, here’s a memo of the reply I received when I contacted support because I wasn’t sure about the READ_LOGS permission.

Hey,

I’ll try to give you a brief tour of this permission and how it interacts with Crittercism.

Crittercism does not require the READ_LOGS permission in order to function correctly. However, by enabling this permission (where applicable), it can provide additional useful information with every crash and exception report that Crittercism receives.

The Android API:

The logs permission functions in two very different ways depending on the version of the Android API. For versions 15 and lower, any access to the logs requires this permission, and its inclusion gives complete access to all log entries.

As you mentioned, such a global permission poses a potential security risk, and at the very least raises questions about data separation. For this reason, starting in Jelly Bean (API version 16 and higher), Google changed its policy about log access.

After the policy change READ_LOGS no longer works for API Level 16 and higher. With these versions, each app has access to log entries generated by the app itself.

To enable logcat collection for newer devices, you need to include the following code in the onCreate() method of your main activity:

// create the JSONObject. (Do not forget to import org.json.JSONObject!) 
JSONObject crittercismConfig = new JSONObject(); 
try 
{ 
crittercismConfig.put("shouldCollectLogcat", true); // send logcat data for devices with API Level 16 and higher 
} 
catch (JSONException je){}

Crittercism.init(getApplicationContext(), "", crittercismConfig);

Does that answer your questions? For further details, please refer to our documentation, here https://app.crittercism.com/developers/docs-android#including_logcat .

Best regards,

That’s all from the Gemba.