web/docs/Setup.mdx
import {GradleCode, AndroidCode} from "@theme/Code";
This Tutorial will show you how to set up ACRA and guide you through your initial configuration choices.
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.
Everything you find in this section belongs into the dependencies block:
dependencies {
//here
}
dependencies {
//here
}
Add the following snippet (with the latest version) <GradleCode>
val acraVersion = "<latest version>"
def acraVersion = '<latest version>'
implementation("ch.acra:acra-http:$acraVersion")
implementation "ch.acra:acra-http:$acraVersion"
implementation("ch.acra:acra-mail:$acraVersion")
implementation "ch.acra:acra-mail:$acraVersion"
implementation("ch.acra:acra-core:$acraVersion")
implementation "ch.acra:acra-core:$acraVersion"
More info: Senders
implementation("ch.acra:acra-dialog:$acraVersion")
implementation "ch.acra:acra-dialog:$acraVersion"
implementation("ch.acra:acra-notification:$acraVersion")
implementation "ch.acra:acra-notification:$acraVersion"
implementation("ch.acra:acra-toast:$acraVersion")
implementation "ch.acra:acra-toast:$acraVersion"
Add nothing.
More info: Interactions
Limits how many reports acra sends from one device
<GradleCode>implementation("ch.acra:acra-limiter:$acraVersion")
implementation "ch.acra:acra-limiter:$acraVersion"
Controls when reports are sent (e.g. only on wifi) and can restart an application after a crash
<GradleCode>implementation("ch.acra:acra-advanced-scheduler:$acraVersion")
implementation "ch.acra:acra-advanced-scheduler:$acraVersion"
If you don't already have an Application class, create one.
Creating an Application class
MyApplication extending from android.app.Application (or another subclass of that)application element in your AndroidManifest.xml to reference the new class.ACRA is configured inside your Application class:
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