解决android studio国内开发者Gradle下载慢问题

1.C:\Users\用户.gradle下init.gradle(沒有此文件就新建一個)文件下增加如下代码内容

allprojects{
    repositories {
        def ALIYUN_REPOSITORY_URL = 'http://maven.aliyun.com/nexus/content/groups/public'
        def ALIYUN_JCENTER_URL = 'http://maven.aliyun.com/nexus/content/repositories/jcenter'
        all { ArtifactRepository repo ->
            if(repo instanceof MavenArtifactRepository){
                def url = repo.url.toString()
                if (url.startsWith('https://repo1.maven.org/maven2')) {
                    project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_REPOSITORY_URL."
                    remove repo
                }
                if (url.startsWith('https://jcenter.bintray.com/')) {
                    project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_JCENTER_URL."
                    remove repo
                }
            }
        }
        maven {
        	url ALIYUN_REPOSITORY_URL
            url ALIYUN_JCENTER_URL
        }
    }
}

** 2.android 工程根目录下的的build.gradle文件中配置国内阿里镜像库**

buildscript {
......
    repositories {
        maven { url 'http://maven.aliyun.com/repository/google' }
        maven { url 'http://maven.aliyun.com/repository/jcenter' }
        maven { url 'http://maven.aliyun.com/nexus/content/groups/public' }
        maven { url 'http://maven.aliyun.com/nexus/content/repositories/gradle-plugin' }
        google()
        jcenter()

    }
.....
}

........

allprojects {
    repositories {
        maven { url 'http://maven.aliyun.com/repository/google' }
        maven { url 'http://maven.aliyun.com/repository/jcenter' }
        maven { url 'http://maven.aliyun.com/nexus/content/groups/public' }
        maven { url 'http://maven.aliyun.com/nexus/content/repositories/gradle-plugin' }
        google()
        jcenter()

    }
}

你可能感兴趣的:(gradle,android,studio,google,maven,android)