大概意思就是每次启动Gradle都会sync检查整个工程,但是某些下载项目需要**,所以会下载缓慢甚至下不动,以前oschina(开源中国)提供了jcenter的镜像地址,然后。。开源中国 Maven 镜像库关闭访问
然后我们使用阿里云的,在工程下面有个build.gradle。
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
maven{ url 'http://maven.aliyun.com/nexus/content/repositories/jcenter'}
//google()
//jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
maven{ url 'http://maven.aliyun.com/nexus/content/repositories/jcenter'}
//google()
//jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
当然,如果觉得每次都要设置很麻烦,可以全局设置。
在操作系统当前用户的 HOME 目录,找到 .gradle 文件夹,在这个文件夹下面创建一个文本文件 init.gradle,完整的文件路径可能如下:C:\Users\<name>\.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'
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
}
}
}
整理转载自:
Could not download auto-value.jar(...):No cached version available for offline mod