Back to Acra

Custom Extensions

web/docs/Custom-Extensions.mdx

latest3.6 KB
Original Source

import {GradleCode, AndroidCode} from "@theme/Code";

Implementing an extension

Create a class extending one of the supported interfaces.

It has to be public and have a zero-argument public constructor (as a result, it cannot be an inner class).

Example:

<AndroidCode>
kotlin
class MyAdmin : ReportingAdministrator {
    init {
        Log.d("MyAdmin", "MyAdmin was loaded")
    }
}
java
public MyAdmin implements ReportingAdministrator {
    public MyAdmin() {
        Log.d("MyAdmin", "MyAdmin was loaded");
    }
}
</AndroidCode>
Supported ExtensionsUse Case
CollectorCollect additional custom data not covered by acra
ApplicationStartupCollectorCollector which is also called at startup
ReportInteractionUsually not needed, as the provided options (dialog, notification, toast) cover all reasonable choices
ReportingAdministratorControl when reports are generated and when the application should be stopped
ReportSenderFactoryRegister custom report senders
ConfigurationBuilderFactoryRegister custom configurations
SenderSchedulerFactoryRegister custom sender scheduler, e.g. to prevent report sending based on custom conditions
StartupProcessorDo something ACRA related on app start

Registering an extension

Choose one of the following alternatives:

By annotation

Add the following dependencies: <GradleCode>

kotlin
compileOnly("com.google.auto.service:auto-service-annotations:1.1.1")
//either for java sources:
annotationProcessor("com.google.auto.service:auto-service:1.1.1")
//or for kotlin sources (requires kapt gradle plugin):
kapt("com.google.auto.service:auto-service:1.1.1")
//or for ksp(requires ksp gradle plugin):
ksp("dev.zacsweers.autoservice:auto-service-ksp:1.1.0")
ksp("com.google.auto.service:auto-service:1.1.1")
groovy
compileOnly "com.google.auto.service:auto-service-annotations:1.1.1"
//either for java sources:
annotationProcessor "com.google.auto.service:auto-service:1.1.1"
//or for kotlin sources (requires kapt gradle plugin):
kapt "com.google.auto.service:auto-service:1.1.1"
//or for ksp(requires ksp gradle plugin):
ksp "dev.zacsweers.autoservice:auto-service-ksp:1.1.0"
ksp "com.google.auto.service:auto-service:1.1.1"
</GradleCode>

Then annotate your extension with the following:

<AndroidCode>
kotlin
@AutoService(<ExtensionInterface>::class)
java
@AutoService(<ExtensionInterface>.class)
</AndroidCode>

By file

To manually register your extension, create a text file in src/main/resources/META-INF/services/ named after the fully qualified interface name (e.g., org.acra.sender.ReportSenderFactory) containing the fully qualified name of your implementation class:

com.example.myapp.MySenderFactory

Your implementation must be public and have a public zero-argument constructor.

See ServiceLoader for more details.