Setup
This Tutorial will show you how to set up ACRA and guide you through your initial configuration choices.
Prerequisites
This guide assumes you are using com.android.tools.build:gradle:4.0.0 or later.
Acra requires at least java 11. This can be configured in various ways, our examples use toolchains for Java and Kotlin.
Dependencies
Everything you find in this section belongs into the dependencies block:
- Kotlin
- Groovy
dependencies {
//here
}
dependencies {
//here
}
Define ACRA Version
Add the following snippet (with the latest version)
- Kotlin
- Groovy
val acraVersion = "<latest version>"
def acraVersion = '<latest version>'
Choose sender
- Http:
- Kotlin
- Groovy
implementation("ch.acra:acra-http:$acraVersion")
implementation "ch.acra:acra-http:$acraVersion"
- Email:
- Kotlin
- Groovy
implementation("ch.acra:acra-mail:$acraVersion")
implementation "ch.acra:acra-mail:$acraVersion"
- Custom:
- Kotlin
- Groovy
implementation("ch.acra:acra-core:$acraVersion")
implementation "ch.acra:acra-core:$acraVersion"
More info: Senders
Choose interaction
- Dialog:
- Kotlin
- Groovy
implementation("ch.acra:acra-dialog:$acraVersion")
implementation "ch.acra:acra-dialog:$acraVersion"
- Notification:
- Kotlin
- Groovy
implementation("ch.acra:acra-notification:$acraVersion")
implementation "ch.acra:acra-notification:$acraVersion"
- Toast:
- Kotlin
- Groovy
implementation("ch.acra:acra-toast:$acraVersion")
implementation "ch.acra:acra-toast:$acraVersion"
- Silent:
Add nothing.
More info: Interactions
Optional Plugins
- Limiter:
Limits how many reports acra sends from one device
- Kotlin
- Groovy
implementation("ch.acra:acra-limiter:$acraVersion")
implementation "ch.acra:acra-limiter:$acraVersion"
- Advanced Scheduler: [since 5.2.0-rc1]
Controls when reports are sent (e.g. only on wifi) and can restart an application after a crash
- Kotlin
- Groovy
implementation("ch.acra:acra-advanced-scheduler:$acraVersion")
implementation "ch.acra:acra-advanced-scheduler:$acraVersion"
Configuration
If you don't already have an Application class, create one.
Creating an Application class
- Create a new class in your package root.
- Give it a name like:
MyApplicationextending fromandroid.app.Application(or another subclass of that) - Update the
applicationelement in yourAndroidManifest.xmlto reference the new class.
ACRA is configured inside your Application class:
- Kotlin
- Java
class MyApplication : Application() {
override fun attachBaseContext(base:Context) {
super.attachBaseContext(base)
initAcra {
//core configuration:
buildConfigClass = BuildConfig::class.java
reportFormat = StringFormat.JSON
//each plugin you chose above can be configured in a block like this:
toast {
text = getString(R.string.acra_toast_text)
//opening this block automatically enables the plugin.
}
}
}
}
public class MyApplication extends Application {
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
ACRA.init(this, new CoreConfigurationBuilder()
//core configuration:
.withBuildConfigClass(BuildConfig.class)
.withReportFormat(StringFormat.JSON)
.withPluginConfigurations(
//each plugin you chose above can be configured with its builder like this:
new ToastConfigurationBuilder()
.withText(getString(R.string.acra_toast_text))
.build()
)
);
}
}
Full configuration options documentation:
See also: Interactions, Senders