Crash Reporting with ACRA

suggest change

Step 1: Add the latest ACRA AAR to the application module build.gradle.

Step 2: Create an Application subclass if you do not have one. Put @ReportsCrashes on that class, not around it, and override attachBaseContext.

Step 3: Call ACRA.init from attachBaseContext after super.attachBaseContext. resToastText applies to ReportingInteractionMode.TOAST. Dialog and notification modes need their own string resources (resDialogText, or the notification title and text).

@ReportsCrashes(
    formUri = "https://your-backend.example/report",
    reportType = HttpSender.Type.JSON,
    httpMethod = HttpSender.Method.POST,
    formUriBasicAuthLogin = "AUTH_USERNAME",
    formUriBasicAuthPassword = "AUTH_PASSWORD",
    customReportContent = {
            ReportField.USER_APP_START_DATE,
            ReportField.USER_CRASH_DATE,
            ReportField.APP_VERSION_CODE,
            ReportField.APP_VERSION_NAME,
            ReportField.ANDROID_VERSION,
            ReportField.DEVICE_ID,
            ReportField.BUILD,
            ReportField.BRAND,
            ReportField.DEVICE_FEATURES,
            ReportField.PACKAGE_NAME,
            ReportField.REPORT_ID,
            ReportField.STACK_TRACE
    },
    mode = ReportingInteractionMode.TOAST,
    resToastText = R.string.crash_text_toast)
public class MyApplication extends Application {
    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        ACRA.init(this);
    }
}

Where AUTH_USERNAME and AUTH_PASSWORD are the credentials of your desired backends.

Step 4: Define the Application class in AndroidManifest.xml

<application android:name=".MyApplication">
    <!-- activities, services, and receivers -->
</application>

Step 5: The app needs the INTERNET permission to send the crash report.

<uses-permission android:name="android.permission.INTERNET"/>

To send a caught exception without showing the crash UI:

ACRA.getErrorReporter().handleSilentException(e);

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents