平时安卓项目编译较慢,其中一个原因就是要下载依赖资源包比较慢。为了解决这个问题,可以配置阿里云镜像,加速下载。
配置方法:
1. 对特定项目生效,在项目中的build.gradle修改内容
1 buildscript { 2 repositories { 3 maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' } 4 maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' } 5 maven { url 'http://maven.aliyun.com/nexus/content/repositories/google' } 6 maven { url 'http://maven.aliyun.com/nexus/content/repositories/gradle-plugin' } 7 } 8 dependencies { 9 classpath 'com.android.tools.build:gradle:3.2.1' 10 } 11 } 12 13 allprojects { 14 repositories { 15 maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' } 16 maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' } 17 maven { url 'http://maven.aliyun.com/nexus/content/repositories/google' } 18 maven { url 'http://maven.aliyun.com/nexus/content/repositories/gradle-plugin' } 19 } 20 }
2. 对所有项目生效
在用户/.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 } } }
来源:https://www.cnblogs.com/qianmaoliugou/p/12369654.html