Skip to main content

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 java 8 (native, not RetroLambda or similar):

build.gradle.kts
android {
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
}

Dependencies

Everything you find in this section belongs into the dependencies block:

build.gradle.kts
dependencies {
//here
}

Define ACRA Version

Add the following snippet (with the latest version)

val acraVersion = "<latest version>"

Choose sender

  • Http:
implementation("ch.acra:acra-http:$acraVersion")
  • Email:
implementation("ch.acra:acra-mail:$acraVersion")
  • Custom:
implementation("ch.acra:acra-core:$acraVersion")

More info: Senders

Choose interaction

  • Dialog:
implementation("ch.acra:acra-dialog:$acraVersion")
  • Notification:
implementation("ch.acra:acra-notification:$acraVersion")
  • Toast:
implementation("ch.acra:acra-toast:$acraVersion")
  • Silent:

Add nothing.

More info: Interactions

Optional Plugins

  • Limiter:

Limits how many reports acra sends from one device

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

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: MyApplication extending from android.app.Application (or another subclass of that)
  • Update the 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.
}
}
}
}

Full configuration options documentation:

See also: Interactions, Senders