How to set up ACRA 5.11.2 in Java Android app to send error reports to server?

58 Views Asked by At

I have a similar to question to this one, in that I am upgrading the ACRA library in my Android (Java) project.

I was also using annotations previously. However, I am upgrading from ch.acra:acra-http:5.5.0 to ch.acra:acra-http:5.11.2 and I cannot work out how to configure ACRA to send its error report to my server script.

With 5.5.0, I was using:

@AcraCore(
        buildConfigClass = BuildConfig.class,
        reportContent = {
                ReportField.USER_CRASH_DATE,
                ReportField.APP_VERSION_NAME,
                ReportField.STACK_TRACE,

                ReportField.ANDROID_VERSION,
                ReportField.PHONE_MODEL,
                ReportField.DEVICE_ID,

                ReportField.TOTAL_MEM_SIZE,
                ReportField.AVAILABLE_MEM_SIZE,

                ReportField.LOGCAT,
                ReportField.APPLICATION_LOG,
                ReportField.CUSTOM_DATA

                //ReportField.USER_COMMENT
        },
        sharedPreferencesName = "ACRA_SHARED_PREFS_3"
)
@AcraHttpSender(
        uri = "http://example.com/crash-reports/android.php",
        httpMethod = HttpSender.Method.POST
)
public class MyApplication extends MultiDexApplication {

    ...

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);

        // The following line triggers the initialization of ACRA
        ACRA.init(this);
    }

}

But I am now very stuck with 5.11.2. Maybe I need to use HttpSenderConfiguration and/or HttpSenderConfigurationBuilder, but I'm not sure how to include it in my code.

With no useful/up-to-date examples on the official site, this non-working code is all I have so far:

protected void attachBaseContext(Context baseContext) {
    super.attachBaseContext(baseContext);

    CoreConfigurationBuilder coreConfigurationBuilder = new CoreConfigurationBuilder();
    coreConfigurationBuilder.setBuildConfigClass(BuildConfig.class);
    coreConfigurationBuilder.setReportFormat(StringFormat.KEY_VALUE_LIST);
    //coreConfigurationBuilder.setPluginConfigurations(); // setPluginConfigurations() method doesn't exist
    coreConfigurationBuilder.setReportContent(
            ReportField.USER_CRASH_DATE,
            ReportField.APP_VERSION_NAME,
            ReportField.STACK_TRACE,

            ReportField.ANDROID_VERSION,
            ReportField.PHONE_MODEL,
            ReportField.DEVICE_ID,

            ReportField.TOTAL_MEM_SIZE,
            ReportField.AVAILABLE_MEM_SIZE,

            ReportField.LOGCAT,
            ReportField.APPLICATION_LOG,
            ReportField.CUSTOM_DATA
    );

    HttpSenderConfigurationBuilder httpSenderConfigurationBuilder = null;
    //httpSenderConfigurationBuilder = coreConfigurationBuilder.getPluginConfigurationBuilder(HttpSenderConfiguration.class); // Not sure what class to pass to getPluginConfigurationBuilder() 
    httpSenderConfigurationBuilder.setUri("http://example.com/crash-reports/android.php");
    httpSenderConfigurationBuilder.setHttpMethod(HttpSender.Method.POST);

    ACRA.init(this, coreConfigurationBuilder);
}

So what code do I need to make ACRA function as it used to when I was using annotations?

0

There are 0 best solutions below