android - 在Android Studio Arctic Fox Canary 8中,app级build.gradle不生成 `allprojects`部分,手动添加时报错

标签 android android-studio gradle

在 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/

相关文章:

android - 将带有 proguard 的 Android 项目迁移到 R8,缺少 rt.java 文件,Android Studio 4.2

java - 安卓工作室 |如何使用 On Click 在 fragment 和 activity 之间切换

eclipse - Gradle(gradlew)在尝试构建Spring Social时无法正确构建Eclipse路径

android - 任务 ':react-native-custom-tabs:transformDexArchiveWithExternalLibsDexMergerForDebugAndroidTest'的执行失败

Android:动画菜单图标

Android 列表格式

Android Studio 光标显示错误

android - 如何保护我的应用免受盗版

java - 将图像导入到我的主 Activity XML 文件后引发 java.lang.NullPointerException 异常

android - 安卓工作室错误 : Incremental out directory should be set to aar output directory