这里只是个转载哈,怕以后用的时候找不到,自己记录下。
非常感谢原文作者让我们提高了很多效率哈哈
https://zhuanlan.zhihu.com/p/26019083
很多人用Android Studio,最不爽的就是下载包依赖非常的缓慢。这是因为国内bintray网站访问速度很慢。谢谢阿里云,给我们提供了bintray jcenter mirror。如果想用阿里云的jcenter加速,请在用户目录/.gradle里放上下面的配置文件init.gradle,即可自动将依赖改为从阿里云下载。
gradle.projectsLoaded {
rootProject.allprojects {
buildscript {
repositories {
def REPOSITORY_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')
|| url.startsWith('https://jcenter.bintray.com/')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $REPOSITORY_URL."
println("buildscript ${repo.url} replaced by $REPOSITORY_URL.")
remove repo
}
}
}
jcenter {
url REPOSITORY_URL
}
}
}
repositories {
def REPOSITORY_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')
|| url.startsWith('https://jcenter.bintray.com/')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $REPOSITORY_URL."
println("allprojects ${repo.url} replaced by $REPOSITORY_URL.")
remove repo
}
}
}
jcenter {
url REPOSITORY_URL
}
}
}
}
好了OK了:)
再次感谢原文作者