【问题标题】:Plugin with id 'com.google.gms:google-services' not found. Flutter未找到 ID 为“com.google.gms:google-services”的插件。扑
【发布时间】:2019-08-13 01:53:01
【问题描述】:

我是 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 中构建后,我得到了错误: “错误:未找到 ID 为 'com.google.gms:google-services' 的插件。” enter image description here

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

【问题讨论】:

  • 转到您的 Android Studio SDK 管理器并在 SDK 工具中检查是否安装了 Google Play Services 和 Google Repository。
  • 您好,欢迎来到 StackOverflow,如果您能引用您已经尝试过的其他解决方案或对其进行解释,那将非常有用。那么您将不会收到重复的答案,并且可能的回答者会知道要避免什么。
  • @Ryosuke 是的,我已经安装了这两个。

标签: android flutter flutter-dependencies


【解决方案1】:

在你的 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

其实谷歌是正确的:classpath 'com.google.gms:google-services:4.2.0' 是正确的,apply plugin: 'com.google.gms.google-services' 也是正确的。一个有冒号,一个有句号。但是名称是如此相似,以至于很容易认为它们应该是相同的。 只要记住“classpath” - 冒号,“plugin” - PERIOD。

【讨论】:

  • 没有帮助我...我遇到了插件问题com.google.gms.google-services not found ...
【解决方案2】:

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

【讨论】:

    【解决方案3】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-14
      • 2021-12-22
      • 2018-09-25
      • 2020-11-13
      • 1970-01-01
      • 1970-01-01
      • 2023-03-23
      相关资源
      最近更新 更多