Back to Acra

Setup

web/docs/Setup.mdx

latest5.2 KB
Original Source

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

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:

<GradleCode>
kotlin
dependencies {
    //here
}
groovy
dependencies {
    //here
}
</GradleCode>

Define ACRA Version

Add the following snippet (with the latest version) <GradleCode>

kotlin
val acraVersion = "<latest version>"
groovy
def acraVersion = '<latest version>'
</GradleCode>

Choose sender

  • Http:
<GradleCode>
kotlin
implementation("ch.acra:acra-http:$acraVersion")
groovy
implementation "ch.acra:acra-http:$acraVersion"
</GradleCode>
  • Email:
<GradleCode>
kotlin
implementation("ch.acra:acra-mail:$acraVersion")
groovy
implementation "ch.acra:acra-mail:$acraVersion"
</GradleCode>
  • Custom:
<GradleCode>
kotlin
implementation("ch.acra:acra-core:$acraVersion")
groovy
implementation "ch.acra:acra-core:$acraVersion"
</GradleCode>

More info: Senders

Choose interaction

  • Dialog:
<GradleCode>
kotlin
implementation("ch.acra:acra-dialog:$acraVersion")
groovy
implementation "ch.acra:acra-dialog:$acraVersion"
</GradleCode>
  • Notification:
<GradleCode>
kotlin
implementation("ch.acra:acra-notification:$acraVersion")
groovy
implementation "ch.acra:acra-notification:$acraVersion"
</GradleCode>
  • Toast:
<GradleCode>
kotlin
implementation("ch.acra:acra-toast:$acraVersion")
groovy
implementation "ch.acra:acra-toast:$acraVersion"
</GradleCode>
  • Silent:

Add nothing.

More info: Interactions

Optional Plugins

  • Limiter:

Limits how many reports acra sends from one device

<GradleCode>
kotlin
implementation("ch.acra:acra-limiter:$acraVersion")
groovy
implementation "ch.acra:acra-limiter:$acraVersion"
</GradleCode>
  • 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

<GradleCode>
kotlin
implementation("ch.acra:acra-advanced-scheduler:$acraVersion")
groovy
implementation "ch.acra:acra-advanced-scheduler:$acraVersion"
</GradleCode>

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:

<AndroidCode>
kotlin
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.
        }
    }
  }
}
java
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()
                )
            );
    }
}
</AndroidCode>

Full configuration options documentation:

See also: Interactions, Senders