Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Flutter and app store releases

Could not find method classpath() for arguments com.google.gms:google-services

ErrorCould not find method classpath() for arguments [com.google.gms:google-services:4.6.0]

Short answer

Gradle only knows classpath() inside buildscript { dependencies { } }. If the line sits in a normal dependencies block, such as the app module's, Gradle cannot find the method. Move it into buildscript, or switch to the plugins block with apply false and delete the classpath line.

  • Applies to Gradle 8.x, Android Gradle Plugin 8.x, Google Services plugin 4.x
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Find every classpath line and see which block it is in. It must be inside buildscript, not in a plain dependencies block.

    grep -rn "classpath\|buildscript" --include=build.gradle --include=build.gradle.kts .
  2. 2Match what you see, then jump to its fix

    1. 1The failing line is in app/build.gradle or in a dependencies block outside buildscriptclasspath is in a normal dependencies blockFix
    2. 2The root build file starts with plugins { ... } and you pasted a classpath line from an older guideThe project already uses the plugins blockFix
    3. 3A copied snippet shows only dependencies { classpath ... } with no buildscript above itclasspath is used in a file that has no buildscript block at allFix

What does the error look like?

  • Could not find method classpath() for arguments [com.google.gms:google-services:4.6.0]
  • Sync fails right after adding the Google Services classpath line from a Firebase setup guide

Cause 1 of 3

classpath is in a normal dependencies block

1Check

Gradle documents classpath only inside buildscript { dependencies { } }. A normal dependencies block is not that place.

sed -n 1,40p build.gradle

2Fix

Put the line inside the buildscript block of the project-level build.gradle, and apply the plugin in the app module.

// project-level build.gradle
buildscript {
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath 'com.google.gms:google-services:4.6.0'
    }
}

// app/build.gradle
apply plugin: 'com.google.gms.google-services'

3Verify

Sync, then build the module.

./gradlew :app:assembleDebug

Confirmed by firebase.google.com

Did this fix it?

Cause 2 of 3

The project already uses the plugins block

1Check

The Firebase setup page now declares the plugin in the root plugins block with its version and apply false, and applies it by id in the module. That setup needs no classpath line.

grep -n "google-services" build.gradle* app/build.gradle*

2Fix

Remove the classpath line, then declare and apply the plugin by id.

// root build.gradle, inside plugins { }
id 'com.google.gms.google-services' version '4.6.0' apply false

// app/build.gradle, inside plugins { }
id 'com.google.gms.google-services'

3Verify

Sync again; the method error should be gone.

./gradlew :app:assembleDebug

Confirmed by firebase.google.com

Did this fix it?

Cause 3 of 3

classpath is used in a file that has no buildscript block at all

1Check

In the Gradle manual, classpath appears together with a repositories declaration for the script itself, inside buildscript. A bare dependencies block does not provide it.

grep -n -B3 "classpath" build.gradle*

2Fix

Wrap the dependency in buildscript with its own repositories, or move to the plugins block as in the second cause.

buildscript {
    repositories { google(); mavenCentral() }
    dependencies { classpath 'com.google.gms:google-services:4.6.0' }
}

3Verify

Run a sync from the command line.

./gradlew help

Confirmed by docs.gradle.org

Did this fix it?

How do I stop it coming back?

  • Copy plugin setup from the vendor's current page, and pick one style (plugins block or buildscript) for the whole project.
  • Keep plugin declarations in the project-level file and only apply them in modules.
  • Check the Firebase setup page for the current plugin version when you upgrade.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Mobile apps

Expo Android push fails because google-services.json is missing

"google-services.json" is missing for firebase

Android push in Expo goes through Firebase Cloud Messaging, which needs two separate things: the google-services.json file inside the app, pointed to by android.googleServicesFile, and a service account key uploaded to Expo for sending.

2 causes, each with a fix

Mobile apps

Flutter Android: Failed to load FirebaseOptions from resource

Failed to load FirebaseOptions from resource. Check that you have defined values.xml correctly.

On Android, Firebase reads its settings from a values.xml file that the Google services Gradle plugin builds from google-services.json.

4 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.