无法初始化 ACRA。找不到方法 getPluginConfigurationBuilder

Can't initialize ACRA. Method getPluginConfigurationBuilder not found

大家好! 我正在尝试在我的 Android 项目中使用 ACRA。我遵循了 ACRA Setup. My app.java file is almost identical to that on ACRA Setup 的建议,但 Android Studio 仍然显示未找到方法 builder.getPluginConfigurationBuilder()。我已经尝试过无数次 Clean / Sync Gradle / Build。我已经升级到最新版本的 AS、AGP 和 Gradle 但没有成功。请帮忙。 PS。前段时间我在另一个项目中使用了 ACRA 的早期版本,使用 ADT 构建没有问题。

ACRA版本:5.9.3(同5.9.1) AS version:Bumblebee 2021.1.1 补丁 2 Gradle版本:7.2 AGP 版本:7.1.2

这是我模块的 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'

}

项目的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(我的应用程序的主模块名称是'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);
    }
}

您的代码适用于 ACRA 5.8。 Java:

的配置在 5.9 中略有变化
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()
        )
   );

我还继续更新了 documentation 以反映该更改