未找到id为'com.google.gms:google-services'的插件。 Flutter。

8

我是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'

在运行flutter run -v或在Android中构建后,我遇到了错误:“ERROR:找不到ID为'com.google.gms:google-services'的插件。”
我尝试了几乎所有在stackoverflow和github上可用的解决方案,但问题仍然存在。

前往您的Android Studio SDK管理器,在SDK工具中检查是否已安装Google Play服务和Google存储库。 - Ryosuke
你好,欢迎来到StackOverflow。如果您能引用或解释一下您已经尝试过的其他解决方案,那将非常有用。这样您就不会收到_重复_的答案,潜在的回答者也会知道要避免什么。 - OriolAbril
@Ryosuke 是的,我已经安装了这两个。 - Mubashir Ali
3个回答

18

在您的 app/build.gradle 文件底部,您有以下内容:

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

这应该实际上是:

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

注意在gmsgoogle-services之间有一个句点,而不是冒号。

编辑:你可能遇到了这个问题,因为Google自己的文档(最后编辑于3月20日)是错误的。我已经向他们发送反馈,希望能够纠正这个问题。 Picture of typo in google doc 存档在这里 http://archive.is/4Ujuc

实际上,Google是正确的:'com.google.gms:google-services:4.2.0'的classpath是正确的,'com.google.gms.google-services'的apply plugin也是正确的。其中一个有一个冒号,另一个有一个句点。但是它们的名称非常相似,很容易认为它们应该相同。 只需记住"classpath" - 冒号,"plugin" - 句点即可。


2
没有帮助我...我遇到了插件com.google.gms.google-services未找到的问题... - Ali Yar Khan

0
如果在应用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)

0

只需删除google-services.json文件,然后重新配置Firebase与您的项目。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接