I'm implementing on my backend side a dashboard to handle the crash reports of my application, however it requires authentication through tokens, and from what I read, the HTTPSenser of ACRA 5.7.0 does not have an option to add headers to the request (at least I didn't find them), so I decided to write my own ReportSender with Retrofit request (so fancy), apparently without much success. The problem is NOT the retrofit request. It never calls the ReportSender.
This is what I tried:
Build.gradle (app)
//ACRA
implementation "ch.acra:acra-core:5.7.0"
implementation "ch.acra:acra-toast:5.7.0"
implementation "ch.acra:acra-http:5.7.0"
// Annotations to register the custom ReportSenderFactory
compileOnly("com.google.auto.service:auto-service-annotations:1.0")
annotationProcessor("com.google.auto.service:auto-service:1.0")
Then my App.Java extends Application
@AcraCore(
buildConfigClass = BuildConfig.class,
reportFormat = StringFormat.JSON,
reportContent = {
ReportField.PACKAGE_NAME,
ReportField.APP_VERSION_NAME,
ReportField.APP_VERSION_CODE,
ReportField.ANDROID_VERSION,
ReportField.PHONE_MODEL,
ReportField.CUSTOM_DATA,
ReportField.STACK_TRACE
}
)
@AcraToast(resText = R.string.sorry)
public class App extends Application
{
@Override
public void onCreate()
{super.onCreate();}
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
ACRA.DEV_LOGGING = true;
ACRA.init(this);
ACRA.getErrorReporter().handleException(new RuntimeException());
}
}
I wrote classes as documentations says: ReportSenderFactory
@AutoService(ReportSenderFactory.class)
public class SenderFactory implements ReportSenderFactory {
@NonNull
@Override
public ReportSender create(@NonNull Context context, @NonNull CoreConfiguration config) {
constants.log("sender","Factory is excuted");
return new Sender();
}
@Override
public boolean enabled(@NonNull CoreConfiguration coreConfig) {
return true;
}
}
And then my customReportSender as follows
public class Sender implements ReportSender {
public Sender() {
constants.log("sender","run constructor");
}
@Override
public void send(@NonNull Context context, @NonNull CrashReportData errorContent) throws ReportSenderException {
constants.log("sender","We should be able to start sending");
}
}
As you can see, Logs are placed at the begginin of every step of the chain processes, so this is what I got as result:
D/ACRA: Building report
D/ACRA: Calling collector org.acra.collector.DropBoxCollector
D/ACRA: Collector org.acra.collector.DropBoxCollector completed
D/ACRA: Calling collector org.acra.collector.ConfigurationCollector
D/ACRA: Collector org.acra.collector.ConfigurationCollector completed
D/ACRA: Calling collector org.acra.collector.DeviceFeaturesCollector
D/ACRA: Collector org.acra.collector.DeviceFeaturesCollector completed
D/ACRA: Calling collector org.acra.collector.CustomDataCollector
D/ACRA: Collector org.acra.collector.CustomDataCollector completed
D/ACRA: Calling collector org.acra.collector.MemoryInfoCollector
D/ACRA: Collector org.acra.collector.MemoryInfoCollector completed
D/ACRA: Calling collector org.acra.collector.SharedPreferencesCollector
D/ACRA: Collector org.acra.collector.SharedPreferencesCollector completed
D/ACRA: Calling collector org.acra.collector.SettingsCollector
D/ACRA: Collector org.acra.collector.SettingsCollector completed
D/ACRA: Calling collector org.acra.collector.TimeCollector
D/ACRA: Calling collector org.acra.collector.StacktraceCollector
D/ACRA: Collector org.acra.collector.TimeCollector completed
D/ACRA: Calling collector org.acra.collector.MediaCodecListCollector
D/ACRA: Collector org.acra.collector.MediaCodecListCollector completed
D/ACRA: Collector org.acra.collector.StacktraceCollector completed
D/ACRA: Calling collector org.acra.collector.LogCatCollector
D/ACRA: Collector org.acra.collector.LogCatCollector completed
D/ACRA: Calling collector org.acra.collector.SimpleValuesCollector
D/ACRA: Calling collector org.acra.collector.ThreadCollector
D/ACRA: Collector org.acra.collector.ThreadCollector completed
D/ACRA: Collector org.acra.collector.SimpleValuesCollector completed
D/ACRA: Calling collector org.acra.collector.DeviceIdCollector
D/ACRA: Collector org.acra.collector.DeviceIdCollector completed
D/ACRA: Calling collector org.acra.collector.DisplayManagerCollector
D/ACRA: Collector org.acra.collector.DisplayManagerCollector completed
D/ACRA: Calling collector org.acra.collector.LogFileCollector
D/ACRA: Collector org.acra.collector.LogFileCollector completed
D/ACRA: Calling collector org.acra.collector.ReflectionCollector
D/ACRA: Calling collector org.acra.collector.PackageManagerCollector
D/ACRA: Collector org.acra.collector.ReflectionCollector completed
D/ACRA: Collector org.acra.collector.PackageManagerCollector completed
D/ACRA: Finishing activities prior to killing the Process
D/ACRA: Finished class com.app.tracker.red.ui.Main
D/ACRA: Writing crash report file /data/user/0/com.app.tracker.red/app_ACRA-unapproved/2021-04-23T15:13:18.113-05:00.stacktrace
D/ACRA: ServicePluginLoader loading services from ServiceLoader : java.util.ServiceLoader[org.acra.interaction.ReportInteraction]
D/ACRA: Checking plugin Configurations : ImmutableList{[org.acra.config.ToastConfiguration@55e6a6b, org.acra.config.HttpSenderConfiguration@76219c8]} for class : class org.acra.config.ToastConfiguration
D/ACRA: Checking plugin Configuration : org.acra.config.ToastConfiguration@55e6a6b against plugin class : class org.acra.config.ToastConfiguration
D/ACRA: Loaded ReportInteraction of type org.acra.interaction.ToastInteraction
D/ACRA: Calling ReportInteraction of class org.acra.interaction.ToastInteraction
D/ACRA: Checking plugin Configurations : ImmutableList{[org.acra.config.ToastConfiguration@55e6a6b, org.acra.config.HttpSenderConfiguration@76219c8]} for class : class org.acra.config.ToastConfiguration
D/ACRA: Checking plugin Configuration : org.acra.config.ToastConfiguration@55e6a6b against plugin class : class org.acra.config.ToastConfiguration
I/Toast: Show toast from OpPackageName:com.app.tracker.red, PackageName:com.app.tracker.red
D/ACRA: Mark 2021-04-23T15:13:18.113-05:00.stacktrace as approved.
D/ACRA: Schedule report sending
D/ACRA: config#reportSenderFactoryClasses : ImmutableList{[]}
D/ACRA: Using PluginLoader to find ReportSender factories
D/ACRA: ServicePluginLoader loading services from ServiceLoader : java.util.ServiceLoader[org.acra.sender.ReportSenderFactory]
D/ACRA: Loaded ReportSenderFactory of type com.app.tracker.red.utils.SenderFactory
D/ACRA: Checking plugin Configurations : ImmutableList{[org.acra.config.ToastConfiguration@55e6a6b, org.acra.config.HttpSenderConfiguration@76219c8]} for class : class org.acra.config.HttpSenderConfiguration
D/ACRA: Checking plugin Configuration : org.acra.config.ToastConfiguration@55e6a6b against plugin class : class org.acra.config.HttpSenderConfiguration
D/ACRA: Checking plugin Configuration : org.acra.config.HttpSenderConfiguration@76219c8 against plugin class : class org.acra.config.HttpSenderConfiguration
D/ACRA: Ignoring disabled ReportSenderFactory of type HttpSenderFactory
D/ACRA: reportSenderFactories : [com.app.tracker.red.utils.SenderFactory@7815b3c]
E/sender: factory is executed
E/sender: run constructor
D/ACRA: Adding reportSender : com.app.tracker.red.utils.Sender@84850c5
D/ACRA: config#reportSenderFactoryClasses : ImmutableList{[]}
D/ACRA: Using PluginLoader to find ReportSender factories
D/ACRA: ServicePluginLoader loading services from ServiceLoader : java.util.ServiceLoader[org.acra.sender.ReportSenderFactory]
D/ACRA: Loaded ReportSenderFactory of type com.app.tracker.red.utils.SenderFactory
D/ACRA: Checking plugin Configurations : ImmutableList{[org.acra.config.ToastConfiguration@55e6a6b, org.acra.config.HttpSenderConfiguration@76219c8]} for class : class org.acra.config.HttpSenderConfiguration
D/ACRA: Checking plugin Configuration : org.acra.config.ToastConfiguration@55e6a6b against plugin class : class org.acra.config.HttpSenderConfiguration
D/ACRA: Checking plugin Configuration : org.acra.config.HttpSenderConfiguration@76219c8 against plugin class : class org.acra.config.HttpSenderConfiguration
D/ACRA: Ignoring disabled ReportSenderFactory of type HttpSenderFactory
D/ACRA: reportSenderFactories : [com.app.tracker.red.utils.SenderFactory@da6ef28]
E/sender: factory is executed
E/sender: run constructor
D/ACRA: Adding reportSender : com.app.tracker.red.utils.Sender@de23441
D/ACRA: Wait for Interactions + worker ended. Kill Application ? True
I/Process: Sending signal. PID: 16285 SIG: 9
I realized that send(context, crashreport) on my custom Sender is never called, (actually constructor is called 3 times but any send()). I tried with the regular HttpSender and works pretty well but it lacks information. Althoug docs are pretty well described, there is not much examples with this version, so I'm beggin for help and guidence. I dont have any clue about what could go wrong.
Hope you guys can help me.