Emailing Reports using ACRA(ver 5.7.0) on Android not working

713 views Asked by At

Im trying to capture the crash logs and send it via mail using ACRA. But the mail is not received.

I have done the following :

1. Initialized ACRA inside the oncreate method of the main activity

ACRA.init(getApplication()); 

2. Specified the Report content

@AcraCore(reportContent = {
        ReportField.REPORT_ID,
        ReportField.USER_APP_START_DATE,
        ReportField.USER_CRASH_DATE,
        ReportField.APP_VERSION_CODE,
        ReportField.APP_VERSION_NAME,
        ReportField.ANDROID_VERSION,
        ReportField.DEVICE_ID,
        ReportField.BRAND,
        ReportField.BUILD,
        ReportField.DEVICE_FEATURES,
        ReportField.PACKAGE_NAME,
        ReportField.REPORT_ID,
        ReportField.STACK_TRACE,
        ReportField.APPLICATION_LOG,
        ReportField.LOGCAT,
        ReportField.USER_EMAIL
},
        reportFormat = JSON,
        reportSenderFactoryClasses = {MainActivity.ACRASenderFactory.class}

)

3. Acrareportsender class below

public class ACRAReportSender implements ReportSender {
    public ACRAReportSender(){
        Log.e("ACRA", "Report Sender created");
    }
    @Override

    public void send(Context context, CrashReportData crashReportData) throws ReportSenderException {
        Log.e("ACRA", "Before sending crash report");
        String reportBody = createCrashReport(crashReportData);
        Intent emailIntent = new Intent(Intent.ACTION_SEND);
        emailIntent.setType("vnd.android.cursor.dir/email");
        String mail[] = {"[email protected]"};
        emailIntent.putExtra(Intent.EXTRA_EMAIL, mail);
        emailIntent.putExtra(Intent.EXTRA_TEXT, reportBody);
        emailIntent.putExtra(Intent.EXTRA_SUBJECT, "ACRA Crash Report");
        context.startActivity(Intent.createChooser(emailIntent, "Send crash to developers by email ..."));
    }
    public String createCrashReport(CrashReportData crashReportData){
        StringBuilder body = new StringBuilder();
        body.append("Device : " + crashReportData.getString(ReportField.BRAND) + " - " + crashReportData.getString(ReportField.PHONE_MODEL))
                .append("\n")
                .append("Android Version : " + crashReportData.getString(ReportField.ANDROID_VERSION))
                .append("\n")
                .append("App Version : " + crashReportData.getString(ReportField.APP_VERSION_CODE))
                .append("\n")
                .append("STACK TRACE : \n" + crashReportData.getString(ReportField.STACK_TRACE));
        return body.toString();

    }
}

4. AcraSenderFactory Class

public class ACRASenderFactory implements ReportSenderFactory {
    public ACRASenderFactory(){
        Log.e("ACRA", "Creating Sender Factory");
    }

    @NonNull
    public ReportSender create(Context context, CoreConfiguration acraConfiguration) {
        Log.e("ACRA", "Returning Report Sender");
        return new ACRAReportSender();
    }
}

Output as verified from logcat ( provided below)

1. 09-01 20:36:06.063  3938  3938 I ACRA    : ACRA is enabled for com.example.myapplication, initializing..    

2. ACRA    : ACRA caught a RuntimeException for com.example.myapplication     

3. 09-01 20:36:06.529  3938  3938 D ACRA    : Building report
09-01 20:36:06.535  3938  4022 D ACRA    : Calling collector org.acra.collector.LogCatCollector
09-01 20:36:06.536  3938  4020 D ACRA    : Calling collector org.acra.collector.DropBoxCollector
09-01 20:36:06.536  3938  4020 D ACRA    : Collector org.acra.collector.DropBoxCollector completed
09-01 20:36:06.536  3938  4020 D ACRA    : Calling collector org.acra.collector.ReflectionCollecto..................
.......................

....................
ACRA    : ServicePluginLoader loading services from ServiceLoader : java.util.ServiceLoader[org.acra.sender.ReportSenderFactory].......
...........................................
...........................................
09-01 20:36:06.586  3938  4010 D ACRA    : Ignoring disabled ReportSenderFactory of type EmailIntentSenderFactory
09-01 20:36:06.586  3938  4010 D ACRA    : reportSenderFactories : []

............................................................................ ............................................................................

09-01 20:36:06.590  3938  4010 D ACRA    : Checking plugin Configuration : org.acra.config.SchedulerConfiguration@1d3f9ef against plugin class : class org.acra.config.HttpSenderConfiguration
09-01 20:36:06.590  3938  4010 D ACRA    : Checking plugin Configuration : org.acra.config.HttpSenderConfiguration@b426cfc against plugin class : class org.acra.config.HttpSenderConfiguration
**09-01 20:36:06.591  3938  4010 D ACRA    : Ignoring disabled ReportSenderFactory of type HttpSenderFactory**

..............................................................
.............................................................
.............................................................
09-01 20:36:06.616  3938  3938 D ACRA    : Ignoring disabled ReportInteraction of type NotificationInteraction
09-01 20:36:06.616  3938  3938 D ACRA    : Mark 2020-09-01T20:36:06.565+05:30.stacktrace as approved.
09-01 20:36:06.617  3938  3938 D ACRA    : Schedule report sending
09-01 20:36:06.626  3938  3938 D ACRA    : config#reportSenderFactoryClasses : ImmutableList{[]}
09-01 20:36:06.626  3938  3938 D ACRA    : Using PluginLoader to find ReportSender factories

The above logs says

a. Acra is getting initialized
b. acra is catching crash
c. report is approved

Query:

  **1. Where am i going wrong. why is it not sending mail**
  2. Is this, **"Ignoring disabled ReportSenderFactory of type HttpSenderFactory"**, as seen from the logs, the reason for not receiving reports via mail? If yes, how this can be rectified ?

Note: in manifest file, Internet permission is provided

1

There are 1 answers

3
F43nd1r On

Your ReportSenderFactory cannot be an inner class. Either make it a toplevel class or declare it static. It also must not be abstract.