将build.gradle中的 jcenter() 改为
maven {url"http://jcenter.bintray.com"}
或者在build.gradle文件中添加
maven{ url'http://maven.aliyun.com/nexus/content/groups/public/' }
maven{ url'http://maven.aliyun.com/nexus/content/repositories/jcenter'}
相关链接 https://blog.csdn.net/lingbulei/article/details/82850448
不要用Android Studio下载gradle,无论如何都不走代理,看见它在下载就马上强行杀进程,因为关不掉的,然后用命令行指定代理,
./gradlew -DsocksProxyHost=127.0.0.1 -DsocksProxyPort=1080 tasks
只要第一次加入这个参数下载zip包,以后就会读取gradle.properties,也可以直接把这个参数加到环境变量GRADLE_OPTS里,再用./gradlew,
export GRADLE_OPTS='-DsocksProxyHost=127.0.0.1 -DsocksProxyPort=1080'
在properties里设置的代理在下载依赖时有用,但是下载gradle本身时不生效,然而,无论怎么设置,AndroidStudio也不会走代理下载gradle,包括AS设置里指定的gradle jvm opts,
gradle镜像全局配置,在gradle安装目录下新建init.gradle文件
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'
def ALIYUN_GOOGLE_URL = 'http://maven.aliyun.com/nexus/content/repositories/google'
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
}
if (url.startsWith('https://dl.google.com/dl/android/maven2/')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_GOOGLE_URL."
remove repo
}
}
}
maven {
url ALIYUN_REPOSITORY_URL
url ALIYUN_JCENTER_URL
url ALIYUN_GOOGLE_URL
}
}
}
下载gradle慢!不是下载依赖包慢!
在gradle-wrapper.properties中将https://services.gradle.org/distributions/ 修改为 https://mirrors.cloud.tencent.com/gradle/