android studio使用gradle构建项目,默认采用的是国外的源,构建项目速度非常慢,可以通过自定义gradle源来加快项目构建速度,以阿里gradle源为例。方法如下,找到addroid studio的gradle路径,通常是:$HOME/.gradle,在该目录下创建文件:init.gradle ,添加以下代码:
[code lang=”bash”]
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
}
}
}
[/code]
重启android studio生效
文章转自:https://www.cnblogs.com/bluestorm/p/12466860.html