關(guān)于Gradle編譯時(shí)下載依賴失敗解決方法

2018年9月18日 AndroidStudio終于更新到了3.2穩(wěn)定版,但是更新之后新建項(xiàng)目總是會(huì)失敗,設(shè)置代理,重新清理各種操作基本上都嘗試遍了,也沒起到作用,花了六個(gè)小時(shí),終于找到了解決方案,在project的build.gradle文件中添加如下內(nèi)容,了解AndroidStudio的看官應(yīng)該一眼就明白了:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        def REPOSITORY_URL = 'http://maven.aliyun.com/nexus/content/groups/public/'
        all { ArtifactRepository repo ->
            if(repo instanceof MavenArtifactRepository){
                def url = repo.url.toString()
                if (url.startsWith('https://repo1.maven.org/maven2') || url.startsWith('https://jcenter.bintray.com/')) {
                    remove repo
                }
            }
        }
        maven {
            url REPOSITORY_URL
        }
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.0'
        

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        def REPOSITORY_URL = 'http://maven.aliyun.com/nexus/content/groups/public/'
        all { ArtifactRepository repo ->
            if(repo instanceof MavenArtifactRepository){
                def url = repo.url.toString()
                if (url.startsWith('https://repo1.maven.org/maven2') || url.startsWith('https://jcenter.bintray.com/')) {
                    remove repo
                }
            }
        }
        maven {
            url REPOSITORY_URL
        }
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

最后,特別鳴謝:https://blog.csdn.net/u013360850/article/details/60595210
阿里的倉(cāng)庫(kù)地址:http://maven.aliyun.com/nexus/content/groups/public/
OSChina的倉(cāng)庫(kù)地址:http://maven.oschina.net/content/groups/public/

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,545評(píng)論 19 139
  • Android 自定義View的各種姿勢(shì)1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 178,983評(píng)論 25 709
  • 用兩張圖告訴你,為什么你的 App 會(huì)卡頓? - Android - 掘金 Cover 有什么料? 從這篇文章中你...
    hw1212閱讀 13,968評(píng)論 2 59
  • 遠(yuǎn)程倉(cāng)庫(kù)的配置在平時(shí)的開發(fā)中,我們往往不會(huì)使用默認(rèn)的中央倉(cāng)庫(kù),默認(rèn)的中央倉(cāng)庫(kù)訪問的速度比較慢,訪問的人或許很多,有...
    kevin0016閱讀 385評(píng)論 0 0
  • 25th Apr. 2018 be proud of 為…自豪. How big of you! I’m so p...
    南陽(yáng)江上閱讀 165評(píng)論 0 0

友情鏈接更多精彩內(nèi)容