136

I have followed this link to integrate ads in my app. But it shows this error:

error image

This is my build.gradle:

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 24
buildToolsVersion "24.0.2"





defaultConfig {
    applicationId "com.example.personal.numbermania"
    minSdkVersion 10
    targetSdkVersion 24
    versionCode 1
    versionName "1.0"
}
buildTypes {
    debug
            {
                debuggable true
            }
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}


dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:24.2.1'
    compile 'com.android.support:design:24.2.1'
    compile 'com.google.firebase:firebase-ads:9.6.0'

}

}

ads are not showing up in real device.please help me This is my error after i updated classpath error

Mohammad Kanan
  • 4,246
  • 10
  • 20
  • 42
Lakshmi
  • 1,391
  • 2
  • 8
  • 10
  • Simply you need to generate `google services json` file from console developers `google` and put it inside `app` directory. – Jay Rathod RJ Oct 10 '16 at 08:44
  • Check this and follow steps given here http://stackoverflow.com/questions/34401143/generate-google-services-json-for-android – Jay Rathod RJ Oct 10 '16 at 08:48
  • where is google services found? – Lakshmi Oct 10 '16 at 09:30
  • Click the link given in answer select your project and get configuration file it will ask you to download file. – Jay Rathod RJ Oct 10 '16 at 09:35
  • Any of the Answer Didn't work. But reset Android Studios solved Check this to reset:- https://stackoverflow.com/questions/19384033/how-to-reset-android-studio – Ujjval Joshi May 15 '21 at 06:00
  • First, add Firebase to your app, you'll get detailed steps on what to do including downloading the required JSON and putting it in your app root folder. Then try this, that should fix the issue. – Yash Joshi May 15 '21 at 19:23

17 Answers17

218

Had the same problem.

Fixed by adding the dependency

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

to the root build.gradle.

https://firebase.google.com/docs/android/setup#manually_add_firebase

Vasily Kabunov
  • 5,655
  • 12
  • 47
  • 49
  • 1
    The documents also stress the importance of adding the `apply plugin: 'com.google.gms.google-services'` at he bottom of the file by writing it in italic. "In your module (app-level) Gradle file (usually app/build.gradle), add a line to the _bottom of the file_." – Joel Broström Mar 21 '19 at 10:21
  • 1
    sir i got error after add above in build.gradle: > Could not find method lasspath() for arguments [com.google.gms:google-services:3.0.0] – Kapil Soni May 07 '19 at 09:17
  • 1
    I'm also getting the `lasspath` error and all I can find on the internet are Kapil Soni's messages that are all left without an answer. So now there's the two of us, sir, you're not alone! – laurent Jun 14 '19 at 07:25
  • 1
    I guess it won't be useful to anybody but Kapil and me, but to fix the `lasspath` issue just run `grep -R 'lasspath' * | grep -i --invert-match 'classpath'` and you should find the file and line that's causing an issue (basically, a typo). – laurent Jun 14 '19 at 07:33
  • Version: classpath 'com.google.gms:google-services:4.3.5 Newest Version number here: 'https://developers.google.com/android/guides/google-services-plugin – Chris Feb 26 '21 at 10:47
  • it shows these depricated warnings ```registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection) registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection) registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)``` – Ali Yar Khan May 14 '21 at 10:43
59

Add classpath com.google.gms:google-services:3.0.0 dependencies at project level build.gradle

Refer the sample block from project level build.gradle

buildscript {
    repositories {
        jcenter()
    }
    dependencies {

        classpath 'com.android.tools.build:gradle:2.3.3'
        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
    }
}
Vasily Kabunov
  • 5,655
  • 12
  • 47
  • 49
eranda.del
  • 2,695
  • 1
  • 14
  • 10
29

You can find the correct dependencies here apply changes to app.gradle and project.gradle and tell me about this, greetings!


Your apply plugin: 'com.google.gms.google-services' in app.gradle looks like this:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.2"

    defaultConfig {
        applicationId "com.example.personal.numbermania"
        minSdkVersion 10
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"

        multiDexEnabled true
    }

    dexOptions {
        incremental true
        javaMaxHeapSize "4g" //Here stablished how many cores you want to use your android studi 4g = 4 cores
    }

    buildTypes {
        debug
                {
                    debuggable true
                }
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
        compile fileTree(include: ['*.jar'], dir: 'libs')
        testCompile 'junit:junit:4.12'
        compile 'com.android.support:appcompat-v7:24.2.1'
        compile 'com.android.support:design:24.2.1'
        compile 'com.google.firebase:firebase-ads:9.6.1'
        compile 'com.google.firebase:firebase-core:9.6.1'
        compile 'com.google.android.gms:play-services:9.6.1'
}

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

Add classpath to the project's gradle:

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

Google play services library on SDK Manager:

enter image description here

19

Had the same problem.

adding this to my dependency didn't solve

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

Adding this solved for me

classpath 'com.google.gms:google-services:+'

to the root build.gradle.

15

Setting up Gradle plugins in the root build.gradle meanwhile works alike this:

plugins {
    id "com.android.application" version "7.2.1" apply false
    id "com.android.library" version "7.2.1" apply false
    id "com.google.gms.google-services" version "4.3.10" apply false
}

Then they can be applied in a module:

plugins {
    id "com.android.application"
    id "com.google.gms.google-services"
}

Unless some Gradle plugin may depend on it, one can remove the buildscript block altogether.

Martin Zeitler
  • 59,798
  • 15
  • 122
  • 186
13

simply add "classpath 'com.google.gms:google-services:3.0.0'" to android/build.gradle to look like this

buildscript {
    repositories {
        maven {
            url "https://maven.google.com"
        }
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        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 also add "apply plugin: 'com.google.gms.google-services'" to the end of file in android/app/build.gradle to look like this

apply plugin: 'com.google.gms.google-services'
Adeojo Emmanuel IMM
  • 1,934
  • 1
  • 17
  • 26
8

Go To Setting > Android SDK > SDK Tools > Google Play Services

enter image description here

Aldan
  • 529
  • 6
  • 20
Keshav Gera
  • 9,806
  • 1
  • 67
  • 48
8

On upgrading to Android Studio 4.2.1, I was prompted to set dependency:

classpath 'com.google.gms:google-services:4.3.7'

However, this caused "Plugin with id 'com.google.gms.google-services' not found".
Leaving it as follows fixed the problem:

classpath 'com.google.gms:google-services:4.3.5'

EDIT:

This problem has now been fixed in:

classpath 'com.google.gms:google-services:4.3.8'
Edmund Johnson
  • 594
  • 8
  • 13
4

In build.gradle(Module:app) add this code

dependencies {
    ……..
    compile 'com.google.android.gms:play-services:10.0.1’
    ……  
}

If you still have a problem after that, then add this code in build.gradle(Module:app)

defaultConfig {
    ….
    …...
    multiDexEnabled true
}


dependencies {
    …..
    compile 'com.google.android.gms:play-services:10.0.1'
    compile 'com.android.support:multidex:1.0.1'
}
  • Result - Adding multiDexEnabled true & compile 'com.android.support:multidex:1.0.1' does not solve the issue. Can you explain how this is supposed to fix the issue? – Ajay B Sep 06 '18 at 11:36
4

I'm not sure about you, but I spent about 30 minutes troubleshooting the same issue here, until I realized that the line for app/build.gradle is:

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

and not:

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

Eg: I had copied that line from a tutorial, but when specifying the apply plugin namespace, no colon (:) is required. It's, in fact, a dot. (.).

Hey... it's easy to miss.

James Perih
  • 1,314
  • 1
  • 15
  • 19
3

Ended up on this thread while trying to integrate Firebase with a Flutter application. So, in case you are facing the same problem in Flutter, below steps solved the issue for me.

Disclaimer: first steps are the same as described in the documentation and every answer/tutorial found online. I am just mentioning them on a high level for the sake of keeping my answer consistent.

The actual step that is different and solved the issue is the last one.

  1. Add google-services.json in your flutter_app/android/app directory.
  2. On android/build.gradle add:
repositories {
    google()
    jcenter()
    maven {
        url "https://maven.google.com"
    }
}

dependencies {
        classpath 'com.android.tools.build:gradle:3.5.0'
        classpath 'com.google.gms:google-services:4.3.4'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }

allprojects {
    repositories {
        google()
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }
}
  1. On android/app/build.gradle add:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
apply plugin: 'com.google.gms.google-services'
  1. On android/app/build.gradle add also the following:
dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

    implementation platform('com.google.firebase:firebase-bom:26.3.0')
    implementation 'com.google.firebase:firebase-analytics'
    implementation 'com.google.firebase:firebase-messaging'

    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}

You can find a working demo for this here https://gitlab.com/ecocupaegean/ecocupaegean/-/tree/master/, in order to run the app you just need to add your own google-services.json, and specify an API KEY for google maps geolocation API.

2

I changed google-services classpath version from 4.2.0 to 3.0.0

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

Then rebuild the project, Then strangely it suggested me to add firebase core to the project.

Then I added firebase core on the app(module)

implementation 'com.google.firebase:firebase-messaging:16.0.8'

Then the error disappeared magically.

2

In the app build.gradle dependency, you must add the following code

classpath 'com.google.gms:google-services:$last_version'

And then please check the Google Play Service SDK tools installing status.

Aldan
  • 529
  • 6
  • 20
GoldCat
  • 41
  • 1
  • 6
1
apply plugin: 'com.google.gms.google-services'

add above line at the bottom of your app gradle.build.

subrahmanyam boyapati
  • 2,770
  • 1
  • 17
  • 28
1

Non of the answers above helped in my case, but following this tutorial thoroughly did. Maps SDK for Android / Set up an Android Studio project

LordScone
  • 2,894
  • 2
  • 16
  • 24
0

In project's build.gradle add the following

classpath 'com.google.gms:google-services:4.3.3'
-1

In android bumblebee Just add this code on top in the build.gradle <Project .> file

buildscript {
    dependencies {
        classpath 'com.google.gms:google-services:4.3.10'
    }
}

Now try to add plugin in build.gradle <app .> like this

plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
    id 'com.google.gms.google-services'
}
UNREAL
  • 152
  • 1
  • 8