Build was configured to prefer settings repositories over project repositories but repository 'ma...

Android Studio 构建错误

出错Studio版本:Android studio arctic Fox

gradle :7.0.3

android studio 版本

今天构建项目的时候提示第三方库报错

Build was configured to prefer settings repositories over project repositories but repository 'maven' was added by build file 'build.gra dle'

或者出现:

Could not find com.xxx.xxx:.
Required by:
    project :app

我已经在 project 的 build.gradle 文件中添加 jitpack.io 作为存储库

buildscript {
    repositories {      
        maven { url 'https://www.jitpack.io' }     
        google()
        mavenCentral()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:7.0.3"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.31"

        // 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 引入了一种定义存储库的新方法。
在项目的 setting.gradledependencyResolutionManagement中添加jitpack.io作为存储库

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        maven { url 'https://www.jitpack.io' }
        google()
        mavenCentral()
        jcenter() // Warning: this repository is going to shut down soon
    }
}

这样基本就没有问题了

你可能感兴趣的:(Build was configured to prefer settings repositories over project repositories but repository 'ma...)