JFed-9 JFed-9 - 2 months ago 38
Android Question

Gradle cannot find google services plugin

I've seen a lot of other questions on SO about this topic, but they're all dealing with things I don't think are relevant to my situation, so I'm making a new question.

In my android app, I am hoping to utilize firebase as my database. However, after copying the google services json file into my 'app' folder, and adding the necessary dependencies in my 'build.gradle' file, it's giving an error, saying 'plugin with id "com.google.gms.google-services" not found'. I'll include the code for my build.gradle, please let me know if I made a mistake somewhere!

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 {

}
}


Notes:

I have tried several options such as:


  • move
    classpath 'com.google.gms:google-services:3.0.0'
    to the bottom in buildscript/dependencies

  • Change
    classpath 'com.google.gms:google-services:3.0.0'
    to
    classpath 'com.google.gms:google-services:1.3.0-beta1'



Thanks in advance!

Answer

First you doing it wrong way its not way to add google play services.You need to compile google play service in project level build gradle first like this

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
    }
}

and then add libraries you need in app level build.gradle like this

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'
Comments