Custom Extensions
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:
- Kotlin
- Java
class MyAdmin : ReportingAdministrator {
init {
Log.d("MyAdmin", "MyAdmin was loaded")
}
}
public MyAdmin implements ReportingAdministrator {
public MyAdmin() {
Log.d("MyAdmin", "MyAdmin was loaded");
}
}
Supported Extensions | Use Case |
---|---|
Collector | Collect additional custom data not covered by acra |
ApplicationStartupCollector | Collector which is also called at startup |
ReportInteraction | Usually not needed, as the provided options (dialog, notification, toast) cover all reasonable choices |
ReportingAdministrator | Control when reports are generated and when the application should be stopped |
ReportSenderFactory | Register custom report senders |
ConfigurationBuilderFactory | Register custom configurations |
SenderSchedulerFactory | Register custom sender scheduler, e.g. to prevent report sending based on custom conditions |
StartupProcessor | Do something ACRA related on app start |
Registering an extension
Choose one of the following alternatives:
By annotation
Add the following dependencies:
- Kotlin
- Groovy
build.gradle.kts
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")
build.gradle
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"
Then annotate your extension with the following:
- Kotlin
- Java
@AutoService(<ExtensionInterface>::class)
@AutoService(<ExtensionInterface>.class)
By file
See ServiceLoader for manual service registration