关于Gradle编译时下载依赖失败解决方法

2018年9月18日 AndroidStudio终于更新到了3.2稳定版,但是更新之后新建项目总是会失败,设置代理,重新清理各种操作基本上都尝试遍了,也没起到作用,花了六个小时,终于找到了解决方案,在project的build.gradle文件中添加如下内容,了解AndroidStudio的看官应该一眼就明白了:

// 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
阿里的仓库地址:http://maven.aliyun.com/nexus/content/groups/public/
OSChina的仓库地址:http://maven.oschina.net/content/groups/public/

你可能感兴趣的:(关于Gradle编译时下载依赖失败解决方法)