美文网首页
Android Studio全局设置阿里镜像

Android Studio全局设置阿里镜像

作者: 放羊娃华振 | 来源:发表于2021-07-20 22:37 被阅读0次

一、单个工程配置

buildscript {
    repositories {
        // 改为阿里云的镜像地址
        maven { url 'https://maven.aliyun.com/repository/central' }
        maven { url 'https://maven.aliyun.com/repository/jcenter' }
        maven { url 'https://maven.aliyun.com/repository/google' }
        maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
        maven { url 'https://maven.aliyun.com/repository/public' }
//        google()
//        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.0.0'
    }
}

allprojects {
    repositories {
        // 改为阿里云的镜像地址
        maven { url 'https://maven.aliyun.com/repository/central' }
        maven { url 'https://maven.aliyun.com/repository/jcenter' }
        maven { url 'https://maven.aliyun.com/repository/google' }
        maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
        maven { url 'https://maven.aliyun.com/repository/public' }
//        google()
//        jcenter()
    }
}

二、全局所有工程配置
先在$GRADLE_USER_HOME/.gradle目录下创建一个叫init.gradle的文件,再添加下面内容

def repoConfig = {
    all { ArtifactRepository repo ->
        if (repo instanceof MavenArtifactRepository) {
            def url = repo.url.toString()
            if (url.contains('repo1.maven.org/maven2') || url.contains('jcenter.bintray.com')) {
                println "gradle init: (${repo.name}: ${repo.url}) removed"
                remove repo
            }
        }
    }

    maven { url 'https://maven.aliyun.com/repository/central' }
    maven { url 'https://maven.aliyun.com/repository/jcenter' }
    maven { url 'https://maven.aliyun.com/repository/google' }
    maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
    maven { url 'https://maven.aliyun.com/repository/public' }
}

allprojects {
    buildscript {
        repositories repoConfig
    }

    repositories repoConfig
}

相关文章

网友评论

      本文标题:Android Studio全局设置阿里镜像

      本文链接:https://www.haomeiwen.com/subject/koxdmltx.html