Android Studio 4.1 Canary:Firebase Crashlytics 中断 android 项目编译

Android Studio 4.1 Canary: Firebase Crashlytics breaks android project compilation

更新: 这已在 Crashlytics Gradle plugin version 2.0.0-beta04 中修复。

我一直在尝试从我正在从事的项目中删除即将弃用的 Fabric Crashlytics SDK,以支持新的 Firebase Crashlytics SDK。不幸的是,之后我在编译时遇到了麻烦。我不断收到以下异常:

Gradle sync failed: No such property: scope for class: com.android.build.gradle.internal.variant.ApplicationVariantData

这是堆栈跟踪:

Caused by: groovy.lang.MissingPropertyException: No such property: scope for class: com.android.build.gradle.internal.variant.ApplicationVariantData
    at com.google.firebase.crashlytics.buildtools.gradle.CrashlyticsPlugin.configureTaskDependencies(CrashlyticsPlugin.groovy:199)
    at com.google.firebase.crashlytics.buildtools.gradle.CrashlyticsPlugin.configureUploadTask(CrashlyticsPlugin.groovy:187)
    at com.google.firebase.crashlytics.buildtools.gradle.CrashlyticsPlugin.registerMappingFileTasks(CrashlyticsPlugin.groovy:142)
    at com.google.firebase.crashlytics.buildtools.gradle.CrashlyticsPlugin$registerMappingFileTasks.callCurrent(Unknown Source)
    at com.google.firebase.crashlytics.buildtools.gradle.CrashlyticsPlugin.registerCrashlyticsTasks(CrashlyticsPlugin.groovy:101)
    at org.gradle.internal.metaobject.BeanDynamicObject$MetaClassAdapter.invokeMethod(BeanDynamicObject.java:483)
    at org.gradle.internal.metaobject.BeanDynamicObject.tryInvokeMethod(BeanDynamicObject.java:195)
    at org.gradle.internal.metaobject.ConfigureDelegate.invokeMethod(ConfigureDelegate.java:77)
    at com.google.firebase.crashlytics.buildtools.gradle.CrashlyticsPlugin$_apply_closure3.doCall(CrashlyticsPlugin.groovy:71)
    at org.gradle.util.ClosureBackedAction.execute(ClosureBackedAction.java:71)
    at org.gradle.util.ConfigureUtil.configureTarget(ConfigureUtil.java:154)
    at org.gradle.util.ConfigureUtil.configure(ConfigureUtil.java:105)
    at org.gradle.util.ConfigureUtil$WrappedConfigureAction.execute(ConfigureUtil.java:166)
    at org.gradle.api.internal.DefaultCollectionCallbackActionDecorator$BuildOperationEmittingAction.run(DefaultCollectionCallbackActionDecorator.java:100)
    at org.gradle.configuration.internal.DefaultUserCodeApplicationContext.reapply(DefaultUserCodeApplicationContext.java:60)
    at org.gradle.api.internal.DefaultCollectionCallbackActionDecorator$BuildOperationEmittingAction.run(DefaultCollectionCallbackActionDecorator.java:97)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:402)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:394)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:165)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:250)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:158)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:92)
    at org.gradle.api.internal.DefaultCollectionCallbackActionDecorator$BuildOperationEmittingAction.execute(DefaultCollectionCallbackActionDecorator.java:94)
    at org.gradle.internal.ImmutableActionSet$SetWithFewActions.execute(ImmutableActionSet.java:285)
    at org.gradle.api.internal.DefaultDomainObjectCollection.doAdd(DefaultDomainObjectCollection.java:264)
    at org.gradle.api.internal.DefaultDomainObjectCollection.add(DefaultDomainObjectCollection.java:253)
    at com.android.build.gradle.AbstractAppExtension.addVariant(AbstractAppExtension.kt:64)
    at com.android.build.gradle.internal.ApiObjectFactory.create(ApiObjectFactory.java:118)
    ... 144 more

我的build.gradle(应用程序)文件:

buildscript {
    repositories {
        jcenter()
        google()
    }

    dependencies {
        classpath 'com.stanfy.spoon:spoon-gradle-plugin:1.2.2'
        classpath "org.jetbrains.dokka:dokka-android-gradle-plugin:$dokka_version"
    }
}

plugins {
    id 'com.gladed.androidgitversion' version '0.4.10'
    id "com.vanniktech.android.junit.jacoco" version "0.15.0"
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'org.jetbrains.dokka-android'
apply plugin: 'com.google.firebase.crashlytics'
apply from: '../app/checkstyle.gradle'
apply from: '../app/ktlint.gradle'
apply from: '../app/androidgit.gradle'

androidExtensions.experimental = true

android {
    compileSdkVersion 29
    defaultConfig {
        applicationId "com.example"
        minSdkVersion 22
        targetSdkVersion 29
        versionName androidGitVersion.name()
        versionCode androidGitVersion.code()
        testInstrumentationRunner "com.example.utils.CustomJUnit4TestRunner"

        // If set to 'true', enables the instrumentation class to start and stop profiling.
        // If set to false (default), profiling occurs the entire time the instrumentation
        // class is running.
        testHandleProfiling true

        // The following argument makes the Android Test Orchestrator run its
        // "pm clear" command after each test invocation. This command ensures
        // that the app's state is completely cleared between tests.
//        testInstrumentationRunnerArguments clearPackageData: 'true'

        // The following argument makes LeakCanary run when instrumentationtests run
//        testInstrumentationRunnerArgument "listener", "leakcanary.FailTestOnLeakRunListener"

        // Upon compilation, export our Room database schema into a JSON file. These represent
        // our database's schema history and are used for database migration testing
        // used by Room, to test migrations
        javaCompileOptions {
            annotationProcessorOptions {
                arguments = [
                        "room.schemaLocation": "$projectDir/schemas".toString(),
                        "room.incremental":"true"
                        // "room.expandProjection":"true"
                ]
            }
        }
    }

    buildFeatures {
        viewBinding = true
    }

    buildTypes {
        debug {
            testCoverageEnabled false
        }
        release {
            shrinkResources true
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    compileOptions {
        // Flag to enable support for the new language APIs
        coreLibraryDesugaringEnabled true
        // Sets Java compatibility to Java 8
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = "1.8"
    }

    ...
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    ...

    // Crashlytics dependencies
    implementation platform("com.google.firebase:firebase-bom:$firebase_bom_version")
    implementation 'com.google.firebase:firebase-crashlytics'
}

有人知道解决这个问题的方法吗?

使用新的 Android Studio 4.1 Canary 时似乎会出现此问题。 我发现的唯一解决方法是返回使用 Android Studio 4.0 Beta,不要忘记也将 Android gradle 插件版本调整为 com.android.tools.build: gradle:4.0.0-beta02.

如果您正在使用 Jetpack Compose 并需要 4.1,我想您将不得不禁用 Crashlytics,直到在 Android Studio 或 Crashlytics 插件中解决此问题。

这已在 Crashlytics Gradle 插件版本 2.0.0-beta04 中修复。

因此升级项目 build.gradle 文件:

...
dependencies {
        classpath "com.android.tools.build:gradle:$gradle_version"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "com.google.firebase:firebase-crashlytics-gradle:2.0.0-beta04"
    }
...