Reputation: 25816
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"
Upvotes: 21
Views: 16212
Reputation: 1647
paste code for your build-script class file in project-level gradle.build file, here is an example :
/**
* project-level - build.gradle file -- make sure buildscript is before
* plugins
**/
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.google.dagger:hilt-android-gradle-plugin:2.41'
}
}
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.1.3' apply false
id 'com.android.library' version '7.1.3' apply false
id 'org.jetbrains.kotlin.android' version '1.6.20' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Upvotes: 2
Reputation: 94
https://docs.gradle.org/7.2/userguide/plugins.html#sec:applying_plugins_buildscript Example 13. Applying a plugin with the buildscript block
buildscript {
repositories {
gradlePluginPortal()
}
dependencies {
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.5'
}
}
apply plugin: 'com.jfrog.bintray'
Upvotes: 1
Reputation: 757
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.
Upvotes: 13
Reputation: 829
add setting.gradle like this
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
jcenter() // Warning: this repository is going to shut down soon
maven { url "https://jitpack.io" }
maven { url "https://android-sdk.tapdaq.com" }
}
}
rootProject.name = "App Name"
include ':app'
buils.gradle(project level)
buildscript {
ext.kotlin_version = "1.6.10"
ext.kotlincoroutine_version = '1.5.1'
ext.coroutineadapter_version = '0.9.2'
ext.gradle_version = '3.5.0'
ext.retrofit_version = '2.9.0'
ext.gson_version = '2.8.7'
ext.okhttp_version = '4.9.0'
ext.glide_version = '4.12.0'
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:7.0.4"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
Upvotes: 0