对于使用 gradle 7.2 创建的 android 项目,项目毕业 和以前的很不一样,现在只包含这些
// 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
}
settings.gradle 也和以前有很大不同,现在包含更多配置,如下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'
在哪里可以添加 classpath 'com.google.gms:google-services:4.3.10'
的类路径?当我将此添加到 settings.gradle 时,它无法编译并出现错误:“在 org.gradle 类型的存储库容器上找不到参数 [com.google.gms:google-services:4.3.10] 的方法 classpath() .api.internal.artifacts.dsl.DefaultRepositoryHandler"
最佳答案
我认为使用 gradle 7.2 版,您实际上不需要指定类路径,请检查 doc1 , doc2 .只需在项目级别 build.gradle 上插入插件 id:
plugins {
...
id "com.google.gms.google-services" version "4.3.10" apply false
}
并且不要忘记将其复制粘贴到应用程序级别的 build.gradle:plugins {
...
id "com.google.gms.google-services"
}
要检查插件是否正确应用,您可以从另一个 answer 打印可用插件列表.
关于android - 在 gradle 7.2 中在哪里以及如何添加类路径依赖项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71610025/