flutter 没有找到ID为“com.google.gms:google-services”的插件,

jaql4c8m  于 2023-01-09  发布在  Flutter
关注(0)|答案(3)|浏览(244)

我是flutter框架的新手。我尝试在flutter中安装cloud firestore,但遇到了问题。以下是我的代码和Gradle文件:安卓系统/构建版本.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
}

应用程序/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'的插件。'

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

cnwbcb6i

cnwbcb6i1#

在您的app/build.gradle文件底部,您可以看到:

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

这实际上应该是:

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

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

**编辑:**您遇到这个问题的原因可能是Google自己的文档(上次编辑时间为3月20日)不正确。我已经向他们发送了反馈,希望他们更正此问题。x1c 0d1x存档在此处http://archive.is/4Ujuc

其实谷歌是正确的:类路径“com.google.gms:google-services:4.2.0”是正确的,并应用插件:“com.google.gms.google-services”也是正确的。一个有冒号,一个有句号。但是这两个名字太相似了,很容易让人认为它们应该是一样的。只要记住“classpath”-冒号,“plugin”-句号就行了。

h79rfbju

h79rfbju2#

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

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)
7vhp5slm

7vhp5slm3#

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

相关问题