在 Android Studio 北极狐金丝雀 8 中创建新项目时,这是应用级别的 build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:7.0.0-alpha08"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.30"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
在 Android Studio 4.1.2 中创建相同的新项目时,应用级 build.gradle 文件是这样的:// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.3.72"
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.1.2"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
我正在使用的库之一需要 allprojects
我手动尝试添加 allprojects
Canary 8 中的部分,收到此错误: problem occurred evaluating root project 'My Application'.
> Build was configured to prefer settings repositories over project repositories but repository 'Google' was added by build file 'build.gradle'
为什么 allprojects
在 Android Studio Canary 8 中已删除,如何将其添加回来以便可以使用这些库?
最佳答案
在 settings.gradle
您可以添加要添加到项目中的存储库
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
jcenter()
maven { url "https://maven.xyz.com" }
}
}
关于android - 在Android Studio Arctic Fox Canary 8中,app级build.gradle不生成 `allprojects`部分,手动添加时报错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66475730/