找不到 ID 为 'com.google.gms:google-services' 的插件。扑

Plugin with id 'com.google.gms:google-services' not found. Flutter

我是 Flutter 框架的新手。我正在尝试在 flutter 中安装 Cloud firestore 但遇到了问题。下面是我的代码和 gradle 文件: Android/build.gradlew:

buildscript {
    // ext.kotlin_version = '1.2.31'
    repositories {
        google()
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        classpath 'com.google.gms:google-services:3.2.0'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

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

App/build.gradle 是:

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion 28

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.example.barcode_app"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
apply plugin: 'com.google.gms:google-services'

在 运行ning flutter 运行 -v 或在 android 中构建它之后我得到了错误: “错误:找不到 ID 为 'com.google.gms:google-services' 的插件。” enter image description here

我尝试了 Whosebug 和 github 上几乎所有可用的解决方案,但问题仍然存在。

在 app/build.gradle 文件的底部,您有:

apply plugin: 'com.google.gms:google-services'

这实际上应该是:

apply plugin: 'com.google.gms.google-services'

注意 gmsgoogle-services 之间的句点,而不是冒号。

编辑: 您遇到这个问题的原因可能是 Google 自己的文档(最后编辑于 3 月 20 日)不正确。我已向他们发送反馈以更正此问题。 存档在这里 http://archive.is/4Ujuc

实际上Google是正确的:类路径'com.google.gms:google-services:4.2.0'是正确的,应用插件:'com.google.gms.google-services'也是正确的。一个有冒号,一个有句点。但是名字如此相似,以至于很容易认为它们应该是一样的。 请记住 "classpath" - 冒号,"plugin" - 句号。

如果在应用 Jmorris 和 Johnhunter 解决方案后问题仍然存在,请检查此 solution

解决方案是:

Upgrade the Android Gradle plugin to 3.5.0
Upgrade the Google Services plugin to 4.3.3
Upgrade Gradle to 5.4.1 (the required Gradle version for this Android Gradle plugin version)

只需删除 google-services.json 文件并使用您的项目重新配置 firebase。