Build was configured to prefer settings repositories over project repositories but repository
首先上链接:stackoverflow的正解
下载了最新版的狐狸图标的AS,4.1.2版本,
新建的项目默认使用的最新版本7.0.2的gradle,
在项目的build.gradle中添加项目编译需要的依赖,
allprojects {
repositories {
google()
jcenter()
}
}
然后,报错,编译不过。提示也说了,构建被配置应该写到 设置存储库 setting.gradle中,而不是项目存储库 build.gradle,但是构建文件'build.gradle'添加了存储库“ Google”。
-
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'
百度没用,Google中搜到了:最新的项目编译依赖配置改到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://jitpack.io' } } }
当然,又试了一下,把setting.gradle中的这个内容删除,添加到项目的build.gradle中,也正常编译运行:
allprojects { repositories { google() mavenCentral() jcenter() // Warning: this repository is going to shut down soon } }
最近有空又了解了一下,在settings.gradle中配置依赖项,是gradle 7.0以后新增的统一管理依赖的方式,上链接: