10

I am trying to add firebase addmob in my app.

In build.gradle(Project) i have following code

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.google.gms: google-services: 3.0.0'
        classpath 'com.android.tools.build:gradle:2.1.3'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

In build.gradle(module)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "24.0.2"

    defaultConfig {
        applicationId "com.myname.examp.myapp"
        minSdkVersion 14
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

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

I have updated version of google play service and repository

enter image description here

When I sync project still i am getting following error

Error:Could not find com.google.gms: google-services: 3.0.0.
Searched in the following locations:
    file:/C:/Program Files/Android/Android Studio2/gradle/m2repository/com/google/gms/ google-services/ 3.0.0/ google-services- 3.0.0.pom
    file:/C:/Program Files/Android/Android Studio2/gradle/m2repository/com/google/gms/ google-services/ 3.0.0/ google-services- 3.0.0.jar
    https://jcenter.bintray.com/com/google/gms/ google-services/ 3.0.0/ google-services- 3.0.0.pom
    https://jcenter.bintray.com/com/google/gms/ google-services/ 3.0.0/ google-services- 3.0.0.jar
Required by:
    :MyApplication:unspecified

Can some one help me how to fix this error

Penny Liu
  • 15,447
  • 5
  • 79
  • 98
scott
  • 3,112
  • 19
  • 52
  • 90
  • Have you added `google-services.json` in your app folder. – Aman Jain Sep 18 '16 at 07:35
  • @AmanJain.Please add this in answer so i can accept your answer.Thanks a lot for your answer.I thought google-services.json is not required while installing library – scott Sep 18 '16 at 09:03
  • Whoever given vote down please tell me why.so i can improve next time.I have explained my question as good as possible – scott Sep 18 '16 at 09:24

9 Answers9

18

I had similar problem, I copied the dependency from the firebase instructions and pasted in code.

From instructions:

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

Supposed to be:

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

Should not include any spaces. Silly but wasted half an hour.

karan vs
  • 3,044
  • 4
  • 19
  • 26
6

Please add google-services.json in your app folder.

Aman Jain
  • 2,975
  • 1
  • 20
  • 35
  • 4
    This does not work for me, even after adding google-service.json file. It still give same error. – karan vs Sep 20 '16 at 05:47
  • This file isn't mentioned anywhere on the instructions with setting up GA. Where do I get this file? – Marty Miller Jun 13 '17 at 02:20
  • @marty Goto Firebase Console > Overview > Project Setting > Download google-services.json https://firebase.google.com/docs/android/setup – Aman Jain Jun 13 '17 at 08:13
3

Add the class path line in the top level gradle file. Not in the same file where you add individual dependencies.

mossman252
  • 462
  • 4
  • 3
2

Move class path dependency to project level build.gradle file as follows :

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.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
    }
}

and ensure that the apply plugin line after dependencies in your build.gradle file in app folder as follows

apply plugin: 'com.google.gms.google-services'
alexander.polomodov
  • 5,396
  • 14
  • 39
  • 46
Annoos
  • 21
  • 1
  • I made a silly mistake. I had `apply from: 'com.google.gms.google-services'` instead of `apply plugin: 'com.google.gms.google-services'`. – Carl Smith Feb 23 '23 at 01:17
0

add the classpath in the build.gradle at your project level not the one in module level.

dependencies {
    classpath 'com.android.tools.build:gradle:2.3.1'
    classpath 'com.google.gms:google-services:3.+'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}

and then apply it in the module level.

apply plugin: 'com.google.gms.google-services'
Gomez NL
  • 912
  • 9
  • 12
0

I had the same error.

I had solved the problem by changing

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

to

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

Maybe you need to downgrade version

Martin JH
  • 101
  • 1
  • 4
0

I was facing similar issue with flutter project for classpath 'com.google.gms:google-services:4.3.15'

For Instance of firebase in app

  1. Go to Firebase Project Click on Flutter Cli
  2. Add firebase cli package in your system https://firebase.google.com/docs/cli?authuser=0&hl=en#install_the_firebase_cli
    curl -sL https://firebase.tools | bash 
    dart pub global activate flutterfire_cli
    firebase login
    flutterfire configure --project=projectId
  1. Add firebase to your project for android/ios
0

I was facing similar issue with flutter project for classpath 'com.google.gms:google-services:4.3.15'

For Instance of firebase in app

  1. Go to Firebase Project Click on Flutter Cli or go run below steps
  2. Add firebase cli package in your system https://firebase.google.com/docs/cli?authuser=0&hl=en#install_the_firebase_cli
    curl -sL https://firebase.tools | bash 
    dart pub global activate flutterfire_cli
    firebase login
    flutterfire configure --project=projectId
  1. Add firebase to your project for android/ios
-2

Error:org.gradle.api.internal.tasks.DefaultTaskInputs$TaskInputUnionFileCollection cannot be cast to org.gradle.api.internal.file.collections.DefaultConfigurableFileCollection Possible causes for this unexpected error include:

  • Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.) Re-download dependencies and sync project (requires network)
  • The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem. Stop Gradle build processes (requires restart)
  • Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.
In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.
Vivek
  • 1