Search code examples
androidacra

Can't initialize ACRA. Method getPluginConfigurationBuilder not found


everyone! I'm trying to use ACRA in my Android project. I have followed recommendations at ACRA Setup. My app.java file is almost identical to that on ACRA Setup, but Android Studio still shows me that method builder.getPluginConfigurationBuilder() was not found. I have tried Clean / Sync Gradle / Build numerous times. I have upgraded to latest versions of AS, AGP and Gradle with no success. Please help. PS. Some time ago I have used earlear versions of ACRA with another project, buld with ADT with no problems.

ACRA version: 5.9.3 (same with 5.9.1) AS version:Bumblebee 2021.1.1 Patch 2 Gradle version: 7.2 AGP version: 7.1.2

This is my module's build.gradle

    apply plugin: 'com.android.application'
android {
    compileSdkVersion 29

    defaultConfig {
        applicationId "com.all.someapp"
        minSdkVersion 19
        targetSdkVersion 29
        versionCode 2
        versionName "1.1"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    compileOptions.encoding = 'windows-1251'
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
//    implementation files('libs/acra-dialog-5.9.1-javadoc.jar')
//    implementation files('libs/acra-mail-5.9.1-javadoc.jar')
//    implementation files('libs/acra-core-5.9.1-javadoc.jar')

    implementation 'androidx.appcompat:appcompat:1.3.1'
    implementation 'androidx.preference:preference:1.1.0'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0'
    implementation 'androidx.activity:activity:1.2.0'
    implementation "androidx.fragment:fragment:1.3.0"
    implementation "androidx.recyclerview:recyclerview:1.2.0"
    implementation 'androidx.navigation:navigation-fragment:2.1.0'
    implementation 'androidx.navigation:navigation-ui:2.1.0'

    def acraVersion = '5.9.1'
    implementation "ch.acra:acra-core:$acraVersion"
    implementation "ch.acra:acra-mail:$acraVersion"
    implementation "ch.acra:acra-dialog:$acraVersion"
    annotationProcessor 'com.google.auto.service:auto-service:1.0.1'
    compileOnly 'com.google.auto.service:auto-service-annotations:1.0.1'

   
    // TEST
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

    implementation 'com.google.android.gms:play-services-location:18.0.0'

}

Projects's build.gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        google()
        jcenter()
        mavenCentral()
        //maven { url 'http://repo1.maven.org/maven2' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:7.1.2'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        mavenCentral()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

app.java (main module name of my application is 'app'):

import android.app.Application;
import android.content.Context;
import org.acra.ACRA;
import org.acra.config.CoreConfigurationBuilder;
import org.acra.config.MailSenderConfigurationBuilder;
import org.acra.data.StringFormat;
import org.acra.mail.BuildConfig;

public class app extends Application {

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);

        CoreConfigurationBuilder builder = new CoreConfigurationBuilder();
        //core configuration:
        builder
                .withBuildConfigClass(BuildConfig.class)
                .withReportFormat(StringFormat.JSON);
        //each plugin you chose above can be configured with its builder like this:
 // !!!============= THIS METHOD CANNOT BE RESOLVED===============!
        builder.getPluginConfigurationBuilder(MailSenderConfigurationBuilder.class)
                
                //make sure to enable all plugins you want to use:
                .withEnabled(true);
        ACRA.init(this, builder);
    }
}

Solution

  • Your code is for ACRA 5.8. Configuration changed slightly in 5.9 for Java:

    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()
                    .withResText(R.string.acra_toast_text)
                    .build()
            )
       );
    

    I also went ahead and updated the documentation reflecting that change