依赖库下载慢的解决办法
经常在AndroidStudio项目中需要用到第三方库,在module的build.gradle中添加依赖后,sync会失败或加载很慢,因为“墙”的原因有一些优秀的技术站无法访问(比如jcenter()问的链接是:https://jcenter.bintray.com/),导致无法下载三方依赖库。
implementation 'com.squareup.okhttp3:okhttp:4.2.2'1、国内仓库
基础设施成熟的公司内部都有搭建私有maven仓库服务器。BAT等第一梯队的互联网公司也向外部给开发提供便利的基础设施。比如:
阿里云仓库站
阿里云公共代理库
2、添加国内仓库
在project的build.gradle中添加国内的maven镜像站点, 访问会很快。
allprojects {
repositories {
maven { url 'https://maven.aliyun.com/repository/google' }
google()
mavenCentral()
maven { url 'https://jitpack.io' }
//maven { url 'https://maven.aliyun.com/repository/jcenter' }
//jcenter()
}
}注意jcenter()库即将关闭,不要再使用。
repositories {
maven { url 'https://maven.aliyun.com/nexus/content/groups/public' }
google()
mavenCentral()
maven { url 'https://jitpack.io' }
//maven { url 'https://maven.aliyun.com/nexus/content/repositories/jcenter' }
//jcenter()
}3、离线依赖库 *
还有一种方法使用本地离线依赖库,参考Maven离线依赖库。
相关博客:
