连接插件“com.google.gms.google-services”时出现错误“没有此类属性:类的 applicationVariants:java.lang.String”

And*_*yev 6 firebase android-studio android-gradle-plugin

我正在使用最新版本的 Android Studio 和所有插件。我正在尝试将 Android 应用程序连接到 firebase 控制台。已成功下载 google-services.json 文件并添加到模块根目录。在 build.gradle 文件中添加了“classpath 'com.google.gms: google-services: 4.3.3”和“apply plugin:' com.google.gms.google-services'”行。

build.gradle项目级别:

buildscript {
    repositories {
        google()
        jcenter()

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.0.1'
        classpath 'com.google.gms:google-services:4.3.3'
        
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()

    }
}
Run Code Online (Sandbox Code Playgroud)

build.gradle应用程序级别:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"
    defaultConfig {
        applicationId "app"
        minSdkVersion 16
        targetSdkVersion 29
        versionCode 42
        versionName "16.0.2"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

    lintOptions {

        checkReleaseBuilds false

    }
}

dependencies {

    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.2.1'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
    implementation 'androidx.navigation:navigation-fragment:2.3.0'
    implementation 'androidx.navigation:navigation-ui:2.3.0'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
    implementation 'com.google.android.gms:play-services-maps:17.0.0'
    implementation 'com.android.support.constraint:constraint-layout:2.0.1'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
    // CloudPayments SDK
    implementation 'ru.cloudpayments.android:sdk:1.0.5'
    // add the Firebase SDK for Google Analytics
    implementation 'com.google.firebase:firebase-iid:20.2.4'
    implementation 'com.google.firebase:firebase-messaging:20.2.4'
    implementation 'com.google.firebase:firebase-analytics:17.5.0'

}

apply plugin: 'com.google.gms.google-services'
Run Code Online (Sandbox Code Playgroud)

同步项目时出现错误

No such property: applicationVariants for class: java.lang.String

它指的是 build.gradle 应用程序级别中的“apply plugin: 'com.google.gms.google-services'”行。

我请求有关如何修复此错误的建议。

小智 0

我通过检查所有 gradle 文件解决了这个问题,并发现 gradle.properties 文件中有一些错误。我不知道\xe2\x80\x99他们是怎么到那里的。但我通过从新的 Android 项目复制内容来替换文件内容。\n已解决

\n