在AndroidStudioArcticFoxCanary8中,app级别的build.gradle不会生成`allprojects`部分并在手动添加时导致错误

在 Android Studio Arctic Fox Canary 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中创建相同的新项目时,app级的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" }
    }
}

  • 这应该是正确答案。

回答

settings.gradle刚刚注释掉整个街区

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {`enter code here`
        google()
        mavenCentral()
        jcenter() // Warning: this repository is going to shut down soon
    }
}


回答

转到setting.gradle并替换该行:

repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)

和:

repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)

这是一个允许它工作的gradle设置。


以上是在AndroidStudioArcticFoxCanary8中,app级别的build.gradle不会生成`allprojects`部分并在手动添加时导致错误的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>