Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where and how to add classpath dependencies in gradle 7.2?

Tags:

android

gradle

For android project created with gradle 7.2, the project gradle is very different from the previous ones, it now only contains these

// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
    id 'com.android.application' version '7.1.2' apply false
    id 'com.android.library' version '7.1.2' apply false
    id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
}

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

The settings.gradle is also very different from before, it now contains more configurations with the following

pluginManagement {
    repositories {
        gradlePluginPortal()
        google()
        mavenCentral()
//        classpath 'com.google.gms:google-services:4.3.10'
    }
}
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
    }
}
rootProject.name = "My App"
include ':app'

Where can I add the classpath for classpath 'com.google.gms:google-services:4.3.10'? When I add this to the settings.gradle, it fails to compile with error: "Could not find method classpath() for arguments [com.google.gms:google-services:4.3.10] on repository container of type org.gradle.api.internal.artifacts.dsl.DefaultRepositoryHandler"

like image 822
s-hunter Avatar asked Nov 23 '25 22:11

s-hunter


1 Answers

I think with gradle version 7.2 you don't really need to specify the classpath, check doc1, doc2. Just insert plugin id on project level build.gradle:

plugins {
    ...
    id "com.google.gms.google-services" version "4.3.10" apply false
}

and don't forget to copy-paste it on app level build.gradle:

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

To check if the plugin is applied correctly, you can print the list of available plugins from another answer.

like image 124
Sky Avatar answered Nov 25 '25 11:11

Sky