After upgrading our app to ACRA 5.9 I found that error reports are sent by HttpSender multiple times.
ACRA is initialized like this:
ACRA.init(this, new CoreConfigurationBuilder()
.withBuildConfigClass(BuildConfig.class)
.withReportFormat(StringFormat.KEY_VALUE_LIST)
.withPluginConfigurations(
new ToastConfigurationBuilder()
.withText(getString(R.string.crash_toast_text))
.build()
)
.withPluginConfigurations(
BuildConfig.DEBUG ?
new LimiterConfigurationBuilder()
.withPeriod(1)
.withPeriodUnit(TimeUnit.DAYS)
.withOverallLimit(250)
.withExceptionClassLimit(100)
.withStacktraceLimit(50)
.withFailedReportLimit(50)
.withIgnoredCrashToast("App stopped working again")
.build() :
new LimiterConfigurationBuilder()
.withPeriod(7)
.withPeriodUnit(TimeUnit.DAYS)
.withOverallLimit(25)
.withExceptionClassLimit(10)
.withStacktraceLimit(5)
.withFailedReportLimit(5)
.withIgnoredCrashToast("App stopped working again")
.build()
)
.withPluginConfigurations(
new HttpSenderConfigurationBuilder()
.withConnectionTimeout(8000)
.withDropReportsOnTimeout(true)
.withUri(fs.getCrashReportUrl())
.build()
)
.withReportContent(fields)
);
Custom HTTP sender is created like this:
@AutoService(ReportSenderFactory.class)
public class MyCrashSenderFactory implements ReportSenderFactory {
private static final String TAG = MyCrashSenderFactory.class.getSimpleName();
@NonNull
public ReportSender create(@NonNull Context context, @NonNull CoreConfiguration config) {
MySettings fs = new MySettings(context);
if (BuildConfig.DEBUG) Log.d(TAG,"ACRA create sender for "+fs.getCrashReportUrl());
return new HttpSender(config, HttpSender.Method.POST, StringFormat.KEY_VALUE_LIST, fs.getCrashReportUrl());
}
@Override
public boolean enabled(@NonNull CoreConfiguration coreConfig) {
return true;
}
}
The logcat after a simple crash looks like this:
14:17:25.358 E ACRA caught a ArithmeticException for com.myapp
java.lang.ArithmeticException: divide by zero
at com.myapp.MenuItemHandler.handleMenuClick(MenuItemHandler.java:128)
...
14:17:25.452 D ACRA create sender for https://api.myapp.com/api/error_report.php
14:17:25.468 D ACRA create sender for https://api.myapp.com/api/error_report.php
14:17:25.511 E USNET: appName: com.myapp:acra
---------------------------- PROCESS STARTED (2569) for package com.myapp ----------------------------
---------------------------- PROCESS ENDED (2036) for package com.myapp ----------------------------
14:17:25.896 D ACRA registered
14:17:25.983 D ACRA create sender for https://api.myapp.com/api/error_report.php
14:17:26.006 I Sending report /data/user/0/com.myapp/app_ACRA-approved/2023-02-11T14:17:25.380+07:00.stacktrace
---------------------------- PROCESS STARTED (2606) for package com.myapp ----------------------------
14:17:27.088 I ACRA is enabled for com.myapp, initializing...
14:17:27.227 D ACRA create sender for https://api.myapp.com/api/error_report.php
14:17:27.237 D ACRA create sender for https://api.myapp.com/api/error_report.php
14:17:27.277 D ACRA create sender for https://api.myapp.com/api/error_report.php
14:17:27.278 I Sending report /data/user/0/com.myapp/app_ACRA-approved/2023-02-11T14:17:25.380+07:00.stacktrace
14:17:27.732 I Request received by server
14:17:28.318 I Request received by server
14:17:28.907 I Request received by server
14:17:29.863 I Request received by server
14:17:29.868 W Could not delete file: /data/user/0/com.myapp/app_ACRA-approved/2023-02-11T14:17:25.380+07:00.stacktrace
The report is sent 4 times. If a custom HTTP sender is not used then 2 times. Is there a way to avoid multiple sends?
EDIT: If I disable the HttpSender by ACRA config I still get about 6 custom HttpSender created and 2 reports sent. Here is the logcat:
---------------------------- PROCESS ENDED (15606) for package com.myapp ----------------------------
---------------------------- PROCESS STARTED (15894) for package com.myapp ----------------------------
08:50:18.794 15894-15894 com.myapp I ACRA is enabled for com.myapp, initializing...
08:50:36.376 15894-15894 com.myapp E ACRA caught a ArithmeticException for com.myapp
java.lang.ArithmeticException: divide by zero
at com.myapp.MenuItemHandler.handleMenuClick(MenuItemHandler.java:128)
...
08:50:36.457 15894-15894 com.myapp D ACRA create sender for https://api.myapp.com/api/error_report.php
08:50:36.466 15894-15894 com.myapp D ACRA create sender for https://api.myapp.com/api/error_report.php
08:50:36.539 16093-16093 pid-16093E USNET: appName: com.myapp:acra
---------------------------- PROCESS STARTED (16093) for package com.myapp ----------------------------
---------------------------- PROCESS ENDED (15894) for package com.myapp ----------------------------
08:50:36.599 16093-16093 com.myapp D handleBindApplication()++ app=com.myapp:acra
08:50:37.040 16093-16120 com.myapp D ACRA create sender for https://api.myapp.com/api/error_report.php
08:50:37.063 16093-16120 com.myapp I Sending report /data/user/0/com.myapp/app_ACRA-approved/2023-02-12T08:50:36.395+07:00.stacktrace
---------------------------- PROCESS STARTED (16128) for package com.myapp ----------------------------
08:50:38.208 16128-16128 com.myapp I ACRA is enabled for com.myapp, initializing...
08:50:38.334 16128-16158 com.myapp D ACRA create sender for https://api.myapp.com/api/error_report.php
08:50:38.341 16128-16158 com.myapp D ACRA create sender for https://api.myapp.com/api/error_report.php
08:50:38.381 16093-16160 com.myapp D ACRA create sender for https://api.myapp.com/api/error_report.php
08:50:38.382 16093-16160 com.myapp I Sending report /data/user/0/com.myapp/app_ACRA-approved/2023-02-12T08:50:36.395+07:00.stacktrace
08:50:38.824 16093-16120 com.myapp I Request received by server
08:50:39.916 16093-16160 com.myapp I Request received by server
08:50:39.925 16093-16160 com.myapp W Could not delete file: /data/user/0/com.myapp/app_ACRA-approved/2023-02-12T08:50:36.395+07:00.stacktrace