出现“错误:ID为'com.google.gms.google-services'的插件”错误

时间:2020-08-19 14:45:00

标签: android android-studio gradle google-play-services

突然我无法构建我的android应用。

以下是我的应用程序级别build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    buildToolsVersion "28.0.3"
    defaultConfig {
        applicationId "com.udayrepo.classelearn"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode 20
        versionName "0.5.6"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true

    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
    }

    android {
        lintOptions {
            warning 'DuplicatePlatformClasses'
        }
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.google.firebase:firebase-core:16.0.1'
    implementation 'com.google.firebase:firebase-config:11.8.0'
    implementation 'com.google.firebase:firebase-ads:15.0.0'
    implementation 'com.google.firebase:firebase-messaging:17.0.0'
    androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.google.android.gms:play-services-ads:11.8.0'
    implementation 'com.github.PhilJay:MPAndroidChart:v3.0.3'
    implementation 'com.google.apis:google-api-services-youtube:v3-rev206-1.25.0'
    implementation 'junit:junit:4.12'
    implementation files('libs/YouTubeAndroidPlayerApi.jar')
    implementation 'com.android.support:multidex:1.0.3'
    implementation 'com.android.support:cardview-v7:28.+'
    implementation('com.foursquare:foursquare-android-oauth:1.0.3') {
        exclude group: 'com.google.android'
    }

    implementation 'com.android.volley:volley:1.1.1'

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

下面是我的项目级别guild.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        google()   //  <--here
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
    }
}

allprojects {
    repositories {
        google()   //  <-- here
        jcenter()
    }
}

当我同步时,出现以下错误: 错误:找不到ID为“ com.google.gms.google-services”的插件。

1 个答案:

答案 0 :(得分:0)

您必须将google-services plugin添加到您的build.gradle文件中。
在您的顶级文件中添加:

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