【Android】Build was configured to prefer settings repositories over project repositories but repository 'maven...解决方案
好久没做Android开发了,加上JFrog跑路,最近把库都转到了JitPack上,但是从gradle版本,和gradle插件版本号在7.0之后,自定义源的方式稍有不同,折腾半天,记录一下。
在之前我们是在build.gradle(project)中去配置:(7.0版本以下都可以用这个方法)
// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { google() jcenter() } dependencies { classpath 'com.android.tools.build:gradle:3.4.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { google() jcenter() maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' } maven { url "https://jitpack.io" } maven { url "http://dl.bintray.com/lukaville/maven" } maven { url "https://maven.google.com/" } } } task clean(type: Delete) { delete rootProject.buildDir }
但是在gradle7.0后使用这种方法会报Build was configured to prefer settings repositories over project repositories but repository 'maven的错误,我们将build.gradle(project)恢复到初始状态:
// 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" // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } task clean(type: Delete) { delete rootProject.buildDir }
然后到项目的setting.gradle中去配置,如下图所示
这样再去Sync就可以了。