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以后新增的统一管理依赖的方式,上链接:

Gradle7.0】依赖统一管理的全新方式

迁移gradle库

  • 116
    点赞
  • 144
    收藏
    觉得还不错? 一键收藏
  • 22
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 22
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值