最近升级到最新版本的Android Studio 发现无法添加第三方Maven仓库,在build.gradle(Project) 中发现只有buildscript {},缺少了之前的allprojects {repositories {…}}配置。
如果我们手动添加allprojects {repositories {…}}时会报错
Build file 'D:\workdemo\ceshishi\build.gradle' line: 20
A problem occurred evaluating root project 'ceshishi'.
> Build was configured to prefer settings repositories over project repositories but repository 'maven' was added by build file 'build.gradle'
解决办法
在项目的根目录(settings.gradle)设置
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
jcenter() // Warning: this repository is going to shut down soon
maven { url 'https://jitpack.io' }
}
}
rootProject.name = "ceshishi"
include ':app'
补充
1、 buildscript里是gradle脚本执行所需依赖,分别是对应的maven库和插件
2、 allprojects里是项目本身需要的依赖,这里基本上我们依赖的三方库。