问题
依赖下载慢或失败
解决方案
- 替换google()和jcenter()源
google()
jcenter()
替换为下面
//google
maven { url 'https://maven.aliyun.com/repository/google' }
//central仓和jcenter仓的聚合仓
maven { url 'https://maven.aliyun.com/repository/public' }
//gradle-plugin
maven { url 'https://maven.aliyun.com/repository/gradle-plugin' } - 替换grade-sdk下载地址
官方镜像distributionUrl=https://services.gradle.org/distributions/gradle-5.1.1-all.zip
csdn镜像distributionUrl=https://downloads.gradle-dn.com/distributions/gradle-5.1.1-all.zip - 全局替换仓库地址
在 ${USER_HOME}.gradle 新建init.gradle,文件内容如下
allprojects{
repositories {
def ALIYUN_REPOSITORY_URL = 'https://maven.aliyun.com/repository/public'
def ALIYUN_JCENTER_URL = 'https://maven.aliyun.com/repository/public'
def ALIYUN_GOOGLE_URL = 'https://maven.aliyun.com/repository/google'
def ALIYUN_GRADLE_PLUGIN_URL = 'https://maven.aliyun.com/repository/gradle-plugin'
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
}
if (url.startsWith('https://plugins.gradle.org/m2/')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_GRADLE_PLUGIN_URL."
remove repo
}
}
}
maven { url ALIYUN_REPOSITORY_URL }
maven { url ALIYUN_JCENTER_URL }
maven { url ALIYUN_GOOGLE_URL }
maven { url ALIYUN_GRADLE_PLUGIN_URL }
}
}
网友评论