【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就可以了。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM