单独工程配置
一、删除 Android Studio 的代理设置
首先你需要确认你已经在 Settings -> Appearance&Behavior -> System Settings -> HTTP Proxy 中选中了 No Proxy。
然后找到项目根目录下的 gradle.properties 文件,打开查看该文件中是否有关于 proxy 设置(代理的地址和端口)的相关语句,删除这些内容
最后,你需要找到你的另一个 gradle.properties 文件:C:\Users\Administrator.gradle\gradle.properties
,删除与 proxy 设置相关的语句
二、让项目通过阿里云 maven jcenter 下载依赖资源
打开项目根目录下的 build.gradle 添加阿里 maven 库地址:
buildscript {
repositories {
// 添加阿里云 maven 地址
maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' }
// jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
// 添加阿里云 maven 地址
maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' }
// jcenter()
google()
}
}
三、重新 SYNC 项目,编译时的资源下载一般就会如丝般顺滑了。
全局配置
一、在C:\Users\用户名\.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
}
}
}