Crashlytics 找不到 Google 服务生成的资源文件。您可能需要执行 :process<Variant>GoogleServices 任务

Crashlytics could not find the resource file generated by Google Services. You may need to execute the :process<Variant>GoogleServices Task

我拿回了一个 1 年多没有更新的旧 android 项目,我尝试用当前的 google 库来设置它。

但我想不出如何解决一个问题:

我的应用程序有 4 个变体:devDebug、devRelease、prodDebug 和 prodRelease。构建项目仅适用于 *Debug 项目。发布变体产生此错误:

Crashlytics could not find the resource file generated by Google Services. You may need to execute the :processGoogleServices Task.Please check your Firebase project configuration (https://firebase.google.com/docs/android/setup).

该应用程序已经注册到 firebase 并且 google-services.json 文件已经存在(我也重新下载以确保)。

根 gradle 文件中的一些代码:

dependencies {
        classpath 'com.android.tools.build:gradle:4.1.0'
        //apt : https://bitbucket.org/hvisser/android-apt
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
        classpath 'com.google.gms:google-services:4.3.4'
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.4.1'
    }

allprojects {
    repositories {
        google()
        jcenter()
        maven {
            url 'https://jitpack.io'
        }
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
    }
}

应用gradle文件的一些代码:

apply plugin: 'com.android.application'

android {

    compileOptions {
        coreLibraryDesugaringEnabled true
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    dexOptions {
        javaMaxHeapSize "4g"
    }

    signingConfigs {
        release_config {
            // config obfuscated
        }
    }
    compileSdkVersion 28
    buildToolsVersion '28.0.3'
    defaultConfig {
        applicationId "my.company.com"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 107
        versionName "1.19.0"

        vectorDrawables.useSupportLibrary = true
        multiDexEnabled true
    }
    
    dataBinding {
        enabled = true
    }
    
    // workaround for "duplicate files during packaging of APK" issue
    // see https://groups.google.com/d/msg/adt-dev/bl5Rc4Szpzg/wC8cylTWuIEJ
    packagingOptions {
        exclude 'META-INF/ASL2.0'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE'

        //Workaround to an issue due to google play-services 11.0.0 + rxJava
        exclude 'META-INF/rxjava.properties'
    }

    lintOptions {
        // Inspired by 
        checkReleaseBuilds false
        abortOnError false
    }

    configurations.all {
        resolutionStrategy {
            force 'com.google.android.gms:play-services-basement:17.0.0'
        }
    }

    buildTypes {
        //Release -> Production version.
        release {
            debuggable false
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release_config

        }
        //Debug -> Development version.
        debug {
            applicationIdSuffix ".debug"
            versionNameSuffix " - debug"
            debuggable true
        }
    }

    flavorDimensions "public"

    productFlavors {
        dev {
            applicationIdSuffix ".dev"
            versionNameSuffix " - dev"
            dimension "public"
        }

        prod {
            dimension "public"
        }

    }
}

ext {
    supportLibVersion = '28.0.0'
}

dependencies {
    implementation group: 'com.google.firebase', name: 'firebase-analytics', version: '17.3.0'
    implementation 'com.google.firebase:firebase-crashlytics:17.3.0'

    // other libraries...
}

apply plugin: 'com.google.firebase.crashlytics'

configurations {
    cleanedAnnotations
    compile.exclude group: 'org.jetbrains', module: 'annotations'
}

欢迎任何提示。

谢谢。

错误实际上是告诉你该怎么做。

在终端 运行:

./gradlew :app:processProdReleaseGoogleServices

./gradlew :app:processDevReleaseGoogleServices