Mac os 全局配置Android阿里云镜像

在当前用户的.gradle文件夹下新建init.gradle文件

Mac os 全局配置Android阿里云镜像_第1张图片
1579059850404.jpg

复制以下内容至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'
        def ALIYUN_GOOGLE_URL = 'http://maven.aliyun.com/nexus/content/repositories/google'
        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
                }
                if (url.startsWith('https://dl.google.com/dl/android/maven2/')) {
                    project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_GOOGLE_URL."
                    remove repo
                }
            }
        }
        maven { url ALIYUN_GOOGLE_URL }
        maven { url ALIYUN_REPOSITORY_URL }
        maven { url ALIYUN_JCENTER_URL }
    }
}

你可能感兴趣的:(Mac os 全局配置Android阿里云镜像)