android gradle使用阿里源

使用阿里源

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

init.gradle 文件内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85

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 文件内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39

## 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