130

Edit, TLDR:

This is most likely a version incompatibility issue. Try to find the compatible google-services Gradle plugin version for your AGP (Android Gradle Plugin) or downgrade your AGP.

The selected answer is updated (almost regularly) with compatible pair.


Old:

I've checked this answer: https://stackoverflow.com/a/34834772/13519865

It tells us to remove this line

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

Removing the line as asked completes the build, but I can't use Firebase (ofc!), it caused a new error, which tells me to add the line: https://stackoverflow.com/a/40085096/13519865

So, I'm stuck in a loop here. Related code sample added here https://github.com/Cyberavater/A.Reader

Cyber Avater
  • 1,494
  • 2
  • 9
  • 25

19 Answers19

248

This issue started after updating the com.android.tools.build:gradle to version 7.3.0 and was fixed for me after updating the com.google.gms:google-services to version 4.3.14.

Roberto Leinardi
  • 10,641
  • 6
  • 65
  • 69
  • 1
    This was exactly my situation. Now working perfectly with the dependency versions you just stated. Thanks. – mlopezv86 Oct 11 '22 at 13:11
  • Thanks so much. I'm primarily an iOS dev and this shows me that there is competition for the quirkiest IDE for Xcode – hulkinggrunt Oct 16 '22 at 10:41
  • 1
    Thanks @Robert This answer fixed the issue. Upgraded Android Studio to Android Studio Electric Eel | 2022.1.1 Patch 1 and Gradle to 7.4.1. 'com.google.gms:google-services:4.3.14' classpath in build.gradle fixed the issue. – Devaski Feb 15 '23 at 15:44
  • 3
    Same for me. Going from `4.3.10` tot `4.3.14` fixed it for me. – SEG.Veenstra May 24 '23 at 08:40
130

Edit: August 15rd, 2023

The same issue seems to appear with the latest Android Studio Electric Giraffe where you need to specify the Gradle version to be 8.1.0 and Google Services 4.3.15. I have not tested if it's working with 5.0.0.

plugins {
    id 'com.android.application' version '8.1.0' apply false
    id 'com.android.library' version '8.1.0' apply false
}

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

Edit: March 24rd, 2023

The same issue seems to appear with the latest Android Studio Electric Eel where you need to specify the Gradle version to be 7.4.0 and Google Services 4.3.15.

plugins {
    id 'com.android.application' version '7.4.0' apply false
    id 'com.android.library' version '7.4.0' apply false
}

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

Edit: January 4th, 2023

I have seen the same issue with the latest Android Studio Dolphin release, where you need to specify the Gradle version to be 7.3.1 and Google Services 4.3.14.

plugins {
    id 'com.android.application' version '7.3.1' apply false
    id 'com.android.library' version '7.3.1' apply false
}

dependencies {
    classpath 'classpath "com.google.gms:google-services:4.3.14'
}

According to the new Chipmunk update of Android Studio, if you need to use Google Services, you have to add the following lines of code inside your build.gradle (Project) file:

plugins {
    id 'com.android.application' version '7.3.1' apply false
    id 'com.android.library' version '7.3.1' apply false
    id 'com.google.gms.google-services' version '4.3.14' apply false 
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

And inside your build.gradle (Module) file, the following plugin IDs:

plugins {
    id 'com.android.application'
    id 'com.google.gms.google-services' 
}
Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
  • Hello, it seems the is a problem still holds. When I used version 4.3.0 following here https://stackoverflow.com/questions/70883309/android-studios-project-gradle-file-changed it was working, but using version 4.3.10 am having the same issue. – Cyber Avater May 13 '22 at 12:58
  • 1
    Execution failed for task ':app:mapDebugSourceSetPaths'. > Error while evaluating property 'extraGeneratedResDir' of task ':app:mapDebugSourceSetPaths' Caused by: org.gradle.api.InvalidUserCodeException: Querying the mapped value of provider(interface java.util.Set) before task ':app:processDebugGoogleServices' has completed is not supported – Cyber Avater May 13 '22 at 12:58
  • 2
    Try to use the latest `7.2.0` for Gradle or downgrade it to `4.3.0`. – Alex Mamo May 13 '22 at 13:00
  • Yes, you are right, Changing it to "7.2.0" worked, Thanks! but isn't '7.4.0-alpha01' more latest? (already latest as it was already '7.4.0-alpha01' by default). – Cyber Avater May 13 '22 at 13:32
  • Yes, but I prefer to work with stable versions. It's up to you to decide if you want to use that one, or not. – Alex Mamo May 13 '22 at 13:48
  • This did not help me and in fact sent me down another rabbit hole of build errors. Roberto Leinardi answer should be accepted as it worked like a charm. So it appears to be gradle and GMS compatibility issue. – MG Developer Oct 03 '22 at 01:31
  • @AlexMamo I can up vote it if you remove the 2nd half of the plugins and clean task portion from your answer. I do not believe they are related to the issue. The reason is my code already had plugin definition and the cleanup task even before the AS upgrade. The only thing that made any difference was version upgrade. Thanks! – MG Developer Oct 09 '22 at 19:25
  • @MGDeveloper I don't understand what you mean by "the 2nd half". Please edit my answer, to understand it more clearly. There is an `edit` button right under it. – Alex Mamo Oct 10 '22 at 06:46
  • If anyone gets this issue in future. This is clearly a version mismatch issue. Try by upgrading version (gms,gradle build) to the most compatible or try by downgrading build.gradle version to the original state and rest to the latest. This worked for me magically. However if you can figure out technically this is a version mismatch issue. – Niranjan Dec 03 '22 at 14:18
  • 2
    It's enough if you just set `4.3.15` as `google-services`! – Rebar Aug 18 '23 at 16:24
  • Still failing in Android Studio Giraffe – Hardik Mehta Aug 23 '23 at 11:15
  • @HardikMehta Are you using Gradle version `8.1.0` and Google Services `4.3.15` and still fails? I doubt it, as I checked that personally. – Alex Mamo Aug 23 '23 at 11:36
  • Don't know fails for me Gradle version 8.1.0 and Google Services 4.3.15 if i degrade Gradle version to 7.4 then works fine – Hardik Mehta Aug 23 '23 at 13:01
70

change this line in >> android/build.gradle

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

to

classpath 'com.google.gms:google-services:4.3.14'
EricAndTheWeb
  • 801
  • 6
  • 4
9

For newbies like myself step by step instructions:

  1. Go to 'android/build.gradle'

  2. Find dependencies {}

  3. Replace there the classpath 'com.google.gms:google-services:4.3.10' with classpath 'com.google.gms:google-services:4.3.14'

  4. Rebuild.

Should work.


The full error text for the search purpose:

Launching lib/main.dart on sdk gphone64 arm64 in debug mode...

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ':app:mapDebugSourceSetPaths'.

Error while evaluating property 'extraGeneratedResDir' of task ':app:mapDebugSourceSetPaths' Failed to calculate the value of task ':app:mapDebugSourceSetPaths' property 'extraGeneratedResDir'. > Querying the mapped value of provider(java.util.Set) before task ':app:processDebugGoogleServices' has completed is not supported

  • Try:

Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

BUILD FAILED in 3s Exception: Gradle task assembleDebug failed with exit code 1 Exited

xao leskii
  • 109
  • 1
  • 2
  • Excellent! I updated Android Studio to the Flamingo version and a lot of problems arrived. One of them was solved with your solution. Thanks. – Ton Jun 29 '23 at 10:21
8

Open your android folder then build.gradle and find

dependencies {
        classpath 'com.android.tools.build:gradle:7.3.0'
        // START: FlutterFire Configuration
        classpath 'com.google.gms:google-services:4.3.10'
        // END: FlutterFire Configuration
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }

and finally change classpath 'com.google.gms:google-services:4.3.10' to classpath 'com.google.gms:google-services:4.3.15' and your code should now look like

dependencies {
        classpath 'com.android.tools.build:gradle:7.3.0'
        // START: FlutterFire Configuration
        classpath 'com.google.gms:google-services:4.3.15'
        // END: FlutterFire Configuration
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }

Hopefully this helps

Cleopas Mwape
  • 101
  • 1
  • 5
5

I was facing the same issues but after updating the dependency the issues were resolved.

in my project level Gradle file previous it was as below:

 dependencies {
        classpath 'com.android.tools.build:gradle:7.3.1'
        classpath 'com.google.gms:google-services:4.3.10'
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.8.1'
        classpath 'com.google.firebase:perf-plugin:1.4.1'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }

after updating as below, It was working fine with me.

dependencies {
        classpath 'com.android.tools.build:gradle:7.3.1'
        classpath 'com.google.gms:google-services:4.3.14'
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.2'
        classpath 'com.google.firebase:perf-plugin:1.4.2'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
urnish
  • 449
  • 3
  • 9
3

In my android/build.gradle for my Flutter project, I had:

classpath 'com.android.tools.build:gradle:4.1.0'
classpath 'com.google.gms:google-services:4.3.10'

I updated by changing the lines to

classpath 'com.android.tools.build:gradle:7.4.2'
classpath 'com.google.gms:google-services:4.3.14'

And the errors were resolved. This happened when I moved my Flutter project to a new laptop and the gradle to java versions no longer matched up since I installed the newest version of Flutter.

2

Read this if Alex Mamo's answer does not solve the problem for you.

The new updates of Android Studio prioritize or prefer the settings.gradle file above build.gradle(project) for plugin management. There are two possible solutions.

Solution 1. Update your existing project as follows.

Update your settings.gradle

pluginManagement {
repositories {
    gradlePluginPortal()
    google()
    mavenCentral()
    gradlePluginPortal()
    jcenter()
    maven {
        url "https://plugins.gradle.org/m2/"}
}
}

dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
    google()
    mavenCentral()
    gradlePluginPortal()
    maven {
        url "https://plugins.gradle.org/m2/"}
}
}
rootProject.name = "Your App Name"
include ':app'

Update your build.gradle(project). Use your Gradle version, this example uses version 7.3.0, and google-services: 4.3.14.

buildscript {
    repositories {
        mavenCentral()
        gradlePluginPortal()
        maven {
            url "https://plugins.gradle.org/m2/"
        }
        google()
        
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:7.3.0'
        classpath 'com.google.gms:google-services:4.3.14'
        classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:0.14.0'
        
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

plugins {
    id 'com.android.application' version '7.3.0' apply false
    id 'com.android.library' version '7.3.0' apply false
    id 'com.google.gms.google-services' version '4.3.14' apply false
    // other plugins in build.gradle(project)
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

Add this to your build.gradle(app)

plugins {
    id 'com.android.application'
    id 'com.google.gms.google-services'
    // other plugins
}

Solution 2. You can create a new project and move all your classes and XML into the new project.

1

Just update you com.google.gms:google-services to latest version.

Prashanth
  • 993
  • 8
  • 18
1

Updating classpath 'com.google.gms:google-services' to the latest version solved the error for me.

1

I encountered same error in Android Studio Giraffe 2022.3.1

By opening android/build.gradle and upgrading the build gradle version to 7.3.1 and Google services version to 4.3.15 my app worked.

1

solved

Replace classpath 'com.google.gms:google-services:4.3.10' with classpath 'com.google.gms:google-services:4.3.14' in android/build.gradle

check the latest gs here : https://developers.google.com/android/guides/google-services-plugin

  • Please don't add "thank you" as an answer. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation), you will be able to [vote up questions and answers](https://stackoverflow.com/help/privileges/vote-up) that you found helpful. - [From Review](/review/late-answers/34900572) – user16217248 Aug 29 '23 at 02:15
0

Try with deleting .idea and .gradle folders from root of your app , an then from main app module ... If this doesn't work , then you must clone your project, making new one with same package name ... This is bug in Android Studio Dolphin , and I solved it with cloning with new project with same package name

0

First check your build.gradle(project) and paste these code below the plugins and also sync your project.

task clean(type: Delete) {
    delete rootProject.buildDir 
}
RusArtM
  • 1,116
  • 3
  • 15
  • 22
0

In Flutter -> Android/build.gradle

buildscript {
    ext.kotlin_version = '1.7.10'
    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:7.3.0'
        // START: FlutterFire Configuration
        classpath 'com.google.gms:google-services:4.3.14'
        // END: FlutterFire Configuration
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}
helvete
  • 2,455
  • 13
  • 33
  • 37
0

In my case, the problem concerned the app/build.gradle where I tend to set three values: (1) compileSdkVersion, (2) minSdkVersion and (3) targetSdkVersion.

On this occasion I found myself setting four values, because a newer version of Android Studio has given me the option, but I was confused, mixing up the "fourth" value with one of the usual three, but it turns out that the fourth value is one that shouldn't be touched, and if you amend it then you'll go around in circles searching for a way to fix the never-ending error messages - hence my encounter with this post.

Example

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

If you see the above within your app/build.gradle file, do not amend it, and if you have amended it, copy what you see here or revert to the default values. Once you set this bit right the error goes away and Flutter runs (if you have set the right settings for the usual three settings).

If this answer helps you, remember to tick it so that it can help others as well.

mathems32
  • 115
  • 9
0

change this line in >> android/build.gradle

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

to

classpath 'com.google.gms:google-services:4.3.14'
toyota Supra
  • 3,181
  • 4
  • 15
  • 19
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 15 '23 at 18:33
0

Go to Android/buil.gradle

replace your dependencies-related code with the following code:

 dependencies {
    classpath 'com.android.tools.build:gradle:7.3.0'
    // START: FlutterFire Configuration
    classpath 'com.google.gms:google-services:4.3.14'
    // END: FlutterFire Configuration
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
0

First delete this lines from your build.gradle file and all related files with google play services ( ads , firebase etc ...)

     dependencies {
        classpath 'com.android.tools.build:gradle:4.2.0'
     //this  delete   classpath 'com.google.gms:google-services:4.3.5'
     //this  delete   classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:[0.12.10, 0.99.99]'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    } 

Then in your app level build.gradle file delete this lines

You must delete all files related to google play service ...

 plugins {
   
//this  delete ======   id 'com.google.gms.google-services'
//this  delete =========   id 'com.onesignal.androidsdk.onesignal-gradle-plugin'
    // Other plugins here if pre-existing if they related to google play services 
}