關於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日,忽見工程妹子喘息,思路足見,不敢停歇,乃廢寢忘食,終的良方,乃記之,以造福后人也。