在Android Studio Arctic Fox Canary 8 中,app 级别的build.gradle 不会生成`allprojects` 部分,并且在手动添加时导致错误 [英] In Android Studio Arctic Fox Canary 8, the app level build.gradle does not generate `allprojects` section and causes error when manually added

查看:19
本文介绍了在Android Studio Arctic Fox Canary 8 中,app 级别的build.gradle 不会生成`allprojects` 部分,并且在手动添加时导致错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Android Studio Arctic Fox Canary 8 中创建新项目时,这是应用级别的 build.gradle

When creating a new project in Android Studio Arctic Fox Canary 8, this is the app level 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中创建同一个新项目时,app级的build.gradle文件是这样的:

When creating the same new project in the Android Studio 4.1.2, the app-level build.gradle file is this:

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

我手动尝试在 Canary 8 中添加 allprojects 部分,收到此错误:

I manually tried to add the allprojects section in Canary 8, received this error:

 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'

为什么 Android Studio Canary 8 中的 allprojects 被删除了,我该如何重新添加它以便我可以使用这些库?

Why was the allprojects in Android Studio Canary 8 was removed and how can I add it back so that I can use the libraries?

推荐答案

settings.gradle 中你可以添加你想要添加到项目中的仓库

In settings.gradle you can add the repositories you want to add to the project

dependencyResolutionManagement {
   repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
   repositories {
      google()
      mavenCentral()
      jcenter()
      maven { url "https://maven.xyz.com" }
    }
}

这篇关于在Android Studio Arctic Fox Canary 8 中,app 级别的build.gradle 不会生成`allprojects` 部分,并且在手动添加时导致错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆