【问题标题】:Gradle cannot find google services pluginGradle 找不到谷歌服务插件
【发布时间】:2016-09-27 21:06:30
【问题描述】:

我在 SO 上看到了很多关于这个主题的其他问题,但他们都在处理我认为与我的情况无关的事情,所以我提出了一个新问题。

在我的 android 应用程序中,我希望使用 firebase 作为我的数据库。但是,在将 google services json 文件复制到我的“app”文件夹中,并在我的“build.gradle”文件中添加必要的依赖项后,它给出了一个错误,说“id 为“com.google.gms.google-services 的插件” “ 未找到'。我将包含我的 build.gradle 的代码,如果我在某个地方犯了错误,请告诉我!

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

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.1"
    defaultConfig {
        applicationId "com.xlr8.jackson.doctrineoropinion" 
        minSdkVersion 15
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-  core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:24.2.1'
    testCompile 'junit:junit:4.12'
    classpath 'com.google.gms:google-services:3.0.0'
}

buildscript {
    dependencies {

    }
}

注意事项:

我尝试了几种选择,例如:

  • 将 classpath 'com.google.gms:google-services:3.0.0' 移到 buildscript/dependencies 的底部
  • 将classpath 'com.google.gms:google-services:3.0.0' 更改为classpath 'com.google.gms:google-services:1.3.0-beta1'

提前致谢!

【问题讨论】:

  • 您是否使用 SDK 管理器下载了最新的 Google 存储库?
  • 我不知道。我有 google-services.json 文件,你指的是这个吗?
  • 谢谢!我去看看
  • apply plugin: 'com.google.gms.google-services' 为什么会有这条线?哪个教程告诉你把它放在那里?

标签: android gradle google-play-services


【解决方案1】:

首先你做错了它不是添加谷歌播放服务的方法。你需要先在项目级构建gradle中编译谷歌播放服务,像这样

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

然后像这样在应用级 build.gradle 中添加您需要的库

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'   


    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.android.support:design:23.4.0'
    compile 'com.android.support:support-v4:23.4.0'

    compile 'com.google.firebase:firebase-messaging:9.6.0'

【讨论】:

    猜你喜欢
    • 2020-02-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多