Gradle - 评估根项目时出现问题 (Android)

Vas*_*val 5 android repository build.gradle

你好,我正在尝试添加此存储库

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}
Run Code Online (Sandbox Code Playgroud)

但不知道为什么我会收到此错误(以前从未发生过)

A problem occurred evaluating root project 'Dog Howl'.
> Build was configured to prefer settings repositories over project repositories but repository 'Google' was added by build file 'build.gradle'
Run Code Online (Sandbox Code Playgroud)

完整代码

// 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.4"
        classpath 'com.google.gms:google-services:4.3.10'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
allprojects {
    repositories {
        google()
        mavenCentral()
    }
}
task clean(type: Delete) {
    delete rootProject.buildDir
}
Run Code Online (Sandbox Code Playgroud)

小智 4

在您的项目中settings.gradle添加您想要的存储库

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