acra icon indicating copy to clipboard operation
acra copied to clipboard

Custom ReportSender is called but send function is never reached

Open draekko opened this issue 2 years ago • 8 comments

Describe the bug Java app using custom email sender to report crash by email, the sender constructor is called but the send function is never called. This used to work in the code but now fails.

Expected behavior send function should be reached to enable custom code to create report and call intent to send email or call createChooser.

Version

  • Android: 11, 13 (A5 / Pixel 2 LOS 18.1, A5 with LOS 20, user Samsung S20 FE (irc) Android 13, emulator API 33)
  • ACRA 5.10.1, 5.11.1, 5.11.3

Tried using several versions of acra core/mail sender versions but i keep getting the same results, tried setting java compatibility to 11 and 17 still no change in the issue. Test with the three above

Took a look at closed issues and saw and tried the solutions in #1132 but that didn't help me at all.

I've also tried adding the enabled method set to false, true or removed completely to the factory.

 @AutoService(ReportSenderFactory.class)
public class CrashEmailReportSenderFactory implements ReportSenderFactory {

    @Override
    public ReportSender create(Context context, CoreConfiguration coreConfiguration) {
        return new CrashEmailReportSender(context, coreConfiguration);
    }

    @Override
    public boolean enabled(@NonNull CoreConfiguration coreConfig) {
        return false;
    }
}

and

 public class CrashEmailReportSender implements ReportSender {
    public CrashEmailReportSender(Context context, CoreConfiguration coreConfiguration) {
        Log.i(TAG, "REPORT CRASH BY EMAIL!");
    }

    @Override
    public boolean requiresForeground() {
        return Build.VERSION.SDK_INT >= VERSION_CODES.Q;
    }

    @Override
    public void send(Context context, CrashReportData crashReportData, Bundle bundle) throws ReportSenderException {
        Log.e(TAG, "============================================================");
        Log.e(TAG, "send(Context, CrashReportData, Bundle)");
        Log.e(TAG, "============================================================");
    }

    @Override
    public void send(Context context, CrashReportData crashReportData) throws ReportSenderException {
        Log.e(TAG, "============================================================");
        Log.e(TAG, "send(Context, CrashReportData)");
        Log.e(TAG, "============================================================");
    }
}

in the application class i have

      if (BuildConfig.DEBUG) {
         ACRA.DEV_LOGGING = true;
      }

      List<ReportField> reportField = new ArrayList<>();
      reportField.add(ReportField.USER_APP_START_DATE);
      reportField.add(ReportField.USER_CRASH_DATE);
      reportField.add(ReportField.APP_VERSION_NAME);
      reportField.add(ReportField.APP_VERSION_CODE);
      reportField.add(ReportField.ANDROID_VERSION);
      reportField.add(ReportField.BRAND);
      reportField.add(ReportField.PRODUCT);
      reportField.add(ReportField.PHONE_MODEL);
      reportField.add(ReportField.REPORT_ID);
      reportField.add(ReportField.STACK_TRACE);
      //reportField.add(ReportField.APPLICATION_LOG);
      reportField.add(ReportField.LOGCAT);

      List<String> logcatArguments = new ArrayList<>();
      logcatArguments.add("-t");
      logcatArguments.add("50000");

      CoreConfigurationBuilder builder = new CoreConfigurationBuilder();

      // WITH
      builder.withBuildConfigClass(BuildConfig.class);
      builder.withReportFormat(StringFormat.JSON);
      builder.withApplicationLogFileDir(Directory.CACHE);
      builder.withApplicationLogFile(BuildConfig.APPLICATION_ID + ".crash.log");
      builder.withApplicationLogFileLines(50000);
      builder.withLogcatArguments(logcatArguments);
      builder.withLogcatReadNonBlocking(false);
      builder.withReportContent(reportField);

      builder.withStopServicesOnCrash(true);
      builder.withSendReportsInDevMode(false);

      // SET
      builder.setBuildConfigClass(BuildConfig.class);
      builder.setReportFormat(StringFormat.JSON);
      builder.setApplicationLogFileDir(Directory.FILES_LEGACY);
      builder.setApplicationLogFile(BuildConfig.APPLICATION_ID + ".crash.log");
      builder.setApplicationLogFileLines(50000);
      builder.setLogcatArguments(logcatArguments);
      builder.setLogcatReadNonBlocking(false);
      builder.setReportContent(reportField);

      builder.setStopServicesOnCrash(true);
      builder.setSendReportsInDevMode(false);

      ACRA.init(application, builder);

I never reach either send methods listed above. i've tried with both .with and .set calls in the application class befoore ACRA.init (including both here for completeness, tried them separately, and together it all fails). i've also tried with and without my logcat arguments same difference. I can see in thelogcat output that the constructor is called but neither of the send methods are called.

including acra filtered parts of logcat. acra-app-logcat.txt

The website api doc seems to be all kt oriented didn't see anything there that was relevant and the java examples on the main site don't seem relevant either. Not sure what else to try at this point.

draekko avatar Feb 18 '24 18:02 draekko

Ignoring disabled ReportSenderFactory of type CrashEmailReportSenderFactory

Your factory was found but disabled.

F43nd1r avatar Feb 18 '24 18:02 F43nd1r

how would i enable it?

draekko avatar Feb 18 '24 18:02 draekko

    @Override
    public boolean enabled(@NonNull CoreConfiguration coreConfig) {
        return true;
    }

or just not override it, as the default implementation already returns true.

F43nd1r avatar Feb 18 '24 18:02 F43nd1r

This is in the factory right? If so i did that already and send never got called, i tied removing it completely, as well as set to false and nothing changed. I'd done that first as well, weird, doesn't make sense why it fails.

Just tried it again as you have it, tried removing it completely, and it fails to reach either send()

also just cycled through VERSION_1_8, VERSION_11, and VERSION_17 for java compatibility in my gradle file and nothing changes send never gets called.

with the override set to true

acra-app-logcat-2.txt

draekko avatar Feb 18 '24 18:02 draekko

One thing i just realized that i should have mentioned the project min sdk is 28 and max sdk is at 30, i can't currently set it higher on this branch due to library issues if i bump it up can't bring it up higher just now. gradle tool plugin is at 7.2.0 and the kotlin grade is at 1.4.32.

draekko avatar Feb 18 '24 19:02 draekko

Most likely your build is in dev mode. With this in your code

builder.setSendReportsInDevMode(false)

no reports will be sent.

By the way the only difference between set and with is that you can chain with-calls as they return the builder.

F43nd1r avatar Feb 18 '24 19:02 F43nd1r

that was the issue, thank you. removed the lines and it reaches it now, guess that didn't do what i thought it was doing.

draekko avatar Feb 18 '24 19:02 draekko

Reopen as tiny enhancement: log a message when a report is swallowed due to dev mode.

F43nd1r avatar Feb 18 '24 19:02 F43nd1r