关于AndroidStudio在编译时无法解析和拉取依赖的问题和无法访问Jcenter服务器的问题
- 先做确认
- JCenter镜像
- 早期依赖仓库(不推荐,可采用JCenter镜像)
- 第三方依赖Maven仓库镜像(添加并拉取第三方依赖时使用)
- 阿里Maven仓库镜像
- 示例文件:
- 后记:
问题描述:
在编译时出现如下错误:
Unknown host ‘d29vzk4ow07wi7.cloudfront.net’. You may need to adjust the…
一般是被墙了。偶发性还能使用,很DT,可以使用JCenter镜像。
再添加依赖后无法拉取依赖:
Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath
一样,被墙了可以使用阿里镜像和第三方镜像解决
先做确认
查看下图是否勾选,取消勾选
JCenter镜像
maven{ url'http://maven.aliyun.com/nexus/content/repositories/jcenter'}
早期依赖仓库(不推荐,可采用JCenter镜像)
mavenCentral()
第三方依赖Maven仓库镜像(添加并拉取第三方依赖时使用)
maven { url "https://jitpack.io" }
阿里Maven仓库镜像
)
maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'}
示例文件:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'}
google()
maven{ url'http://maven.aliyun.com/nexus/content/repositories/jcenter'}
//必须写在JCenter上边
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
maven{ url'http://maven.aliyun.com/nexus/content/repositories/jcenter'}
//必须写在JCenter上边
jcenter()
maven { url "https://jitpack.io" }
maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
后记:
记录一次毁天灭地的被墙奸事件。。。。。
记得那是一个平静的夜晚…星光明媚,本人同舍友在打游戏,在临近23:00分的时候正准备上床碎觉,不料一眼瞥见努力了一个周的工程妹妹浑身鲜血(全是Bug)。
心想坏了,好端端的妹子怎么就被伤害了,我可是对她照顾的无微不至啊,无奈之下尝试修复,未果。次日尝试修复,未果,如此往复三日,放假了。。。我心渐崩溃。
居家中日夜担忧妹子身体安慰,无奈本人平庸四处求医问药,未果。
家中居七日,日日阅百篇博客,虽得方法万千,却依旧无法对症。吾心憔悴矣!进7.11日,忽见工程妹子喘息,思路足见,不敢停歇,乃废寝忘食,终的良方,乃记之,以造福后人也。