应用插件错误:“ com.google.gsm.google-services”还添加了类路径“ com.google.gms:google-services:4.2.0”

时间:2019-08-26 06:33:00

标签: android android-studio gradle

我正在使用Firebase实时数据库。当我想同步gradle时,出现以下错误消息: 找不到ID为“ com.google.gsm.google-services”的插件。

我已经下载了google-services.json并将其添加到项目视图中的我的应用程序文件夹中 并且我已经尝试了许多类路径,包括:

classpath 'com.google.gms:google-services:4.2.0'
classpath 'com.google.gms:google-services:4.3.1'
classpath 'com.google.gms:google-services:3.0.0'

项目gradle:

{buildscript 
    repositories {
        google()
        jcenter()    
}
    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.2'
        classpath 'com.google.gms:google-services:4.2.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()

    }
}

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

我的模块应用是:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.esppad.friendlychat2"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}


dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    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'
    implementation 'com.github.bumptech.glide:glide:3.6.1'
    implementation 'com.google.firebase:firebase-database:19.0.0'

}
apply plugin: 'com.google.gsm.google-services'

2 个答案:

答案 0 :(得分:0)

应用插件:“ com.google.gsm.google-services”不得放置在依赖项中

在如下所示的依赖项之后添加它,

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
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'
implementation 'com.github.bumptech.glide:glide:3.6.1'
implementation 'com.google.firebase:firebase-database:19.0.0'
}

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

答案 1 :(得分:0)

此行中有一个错字:apply plugin: 'com.google.gsm.google-services'应该是gms而不是gsm,如下所示:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.esppad.friendlychat2"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}


dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    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'
    implementation 'com.github.bumptech.glide:glide:3.6.1'
    implementation 'com.google.firebase:firebase-database:19.0.0'
}

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