android gradle使用阿里源

使用阿里源

新建一个init.gradle 文件到$USER_HOME/.gradle/目录下,这们就省的翻墙了。

init.gradle 文件内容如下:

allprojects {
    repositories {
        maven {
            url 'https://maven.aliyun.com/repository/public/'
        }
        maven {
            url 'https://maven.aliyun.com/repository/google/'
        }

        all { ArtifactRepository repo ->
            if (repo instanceof MavenArtifactRepository) {
                def url = repo.url.toString()

                if (url.startsWith('https://repo.maven.apache.org/maven2/') || url.startsWith('https://repo.maven.org/maven2') 
                    || url.startsWith('https://repo1.maven.org/maven2') || url.startsWith('https://jcenter.bintray.com/')
                    || url.startsWith('https://maven.google.com/') || url.startsWith('https://dl.google.com/dl/android/maven2/')) {
                    //project.logger.lifecycle "Repository ${repo.url} replaced by $REPOSITORY_URL."
                    remove repo
                }
            }
        }
    }

    buildscript {
        repositories {
            maven{ url 'https://maven.aliyun.com/repository/public/'}
            maven{ url 'https://maven.aliyun.com/repository/google/'}

            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/')
                         || url.startsWith('https://dl.google.com/dl/android/maven2/')) {
                        //project.logger.lifecycle "Repository ${repo.url} replaced by $REPOSITORY_URL."
                        remove repo
                    }
                }
            }
        }
    }

}

全局翻墙代理配置

同样新建一个gradle.properties 文件到$USER_HOME/.gradle/目录下,如果放在项目目录下,则只对当前项目生效。

gradle.properties 文件内容如下:

## For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
#
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx1024m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
#
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
#Wed Apr 10 21:30:10 CST 2019
systemProp.https.nonProxyHosts=127.0.0.1
systemProp.http.proxyHost=127.0.0.1
systemProp.https.proxyPort=8787
systemProp.http.nonProxyHosts=127.0.0.1
systemProp.https.proxyHost=127.0.0.1
systemProp.http.proxyPort=8787
posted @ 2019-10-11 12:02  至尊王者  阅读(2138)  评论(0编辑  收藏