导入新的工程时经常需要下载好多库,有些库因为种种原因无法下载下来。这时候,可以有以下的解决方案。
解决方法一:
https:改成 http协议下载
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
// jcenter()
jcenter(){url 'http://jcenter.bintray.com/'}
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
// jcenter()
jcenter(){url 'http://jcenter.bintray.com/'}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
方法二:
切换到国内的Maven镜像仓库。
修改项目根目录下 build.gradle 文件,将 jcenter() 或者 mavenCentral() 替换掉即可。
修改成这样
buildscript{
repositories{
maven{ url'http://maven.aliyun.com/nexus/content/groups/public/' }
maven{ url'http://maven.aliyun.com/nexus/content/repositories/jcenter'}
google()
}
dependencies{
classpath'com.android.tools.build:gradle:3.1.4'
// 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'}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
然后,重新同步一下就可以很快下载了
本文提供两种有效方案解决工程库下载问题,一是更改HTTPS为HTTP协议,二是切换至国内Maven镜像仓库,如阿里云,确保项目资源快速稳定获取。
9650





