时间就是金钱,所有浪费时间的事情就是遏制你赚钱
引言:
我们在Android Studio开发过程中,Gradle编译显得尤其重要。特别是我们在下载依赖架包的时候,由于国内“闭关锁国”比较严重,导致下载速度很慢,甚至提示架包找不到,如下面的日志。既然国外的不可靠,国人还是有很多具有当担的人,一如阿里。替换成阿里镜像,就可以完美解决问题。亲测有效
Execution failed for task ':app:lint'.
> Could not resolve all files for configuration ':app:lintClassPath'.
> Could not download XXX.jar (com.android.tools.lint:lint-api:26.1.2)
> Could not get resource 'https://dl.google.com/dl/android/maven2/com/android/tools/lint/lint-api/26.1.2/lint-api-26.1.2.jar'.
> Could not GET 'https://dl.google.com/dl/android/maven2/com/android/tools/lint/lint-api/26.1.2/lint-api-26.1.2.jar'.
> Remote host closed connection during handshake
一 . 单个项目配置
找到对应工程的build.gradle
,在buildscript
和allprojects
中都添加上阿里的maven镜像
buildscript {
repositories {
maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' }
maven { url 'http://maven.aliyun.com/nexus/content/repositories/google' }
maven { url 'http://maven.aliyun.com/nexus/content/repositories/gradle-plugin' }
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
}
}
allprojects {
repositories {
maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' }
maven { url 'http://maven.aliyun.com/nexus/content/repositories/google' }
maven { url 'http://maven.aliyun.com/nexus/content/repositories/gradle-plugin' }
google()
jcenter()
}
}
2.所有项目配置
找到C:\Users\xxx\.gradle
文件夹,一般就是系统盘C 用户下面,在里面新建一个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
}
}
}