今天終于把Android Studio依賴(lài)國(guó)內(nèi)阿里云鏡像搞定

首先百度 “Android Studio 依賴(lài)國(guó)內(nèi)鏡像”

好些文章都是在介紹這個(gè)方式,我試驗(yàn)了一下,行不通。

后來(lái)找到了這篇文章Android Studio配置阿里云鏡像地址,加速依賴(lài)資源下載,感覺(jué)有希望。

于是用里面的鏈接http://maven.aliyun.com/nexus/content/groups/public?訪(fǎng)問(wèn)了一下,如下:

阿里云鏡像

最后訪(fǎng)問(wèn)到了阿里云的鏡像。參考里面的說(shuō)明,我的文件如下:

文件內(nèi)容,用了阿里的最新地址

allprojects{

? ? repositories {

? ? ? ? def ALIYUN_REPOSITORY_URL = 'https://maven.aliyun.com/repository/central'

? ? ? ? def ALIYUN_JCENTER_URL = 'https://maven.aliyun.com/repository/public'

? ? ? ? all { ArtifactRepository repo ->

? ? ? ? ? ? if(repo instanceof MavenArtifactRepository){

? ? ? ? ? ? ? ? def url = repo.url.toString()

? ? ? ? ? ? ? ? if (url.startsWith('https://repo1.maven.org/maven2') || url.startsWith('http://repo1.maven.org/maven2')) {

? ? ? ? ? ? ? ? ? ? project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_REPOSITORY_URL."

? ? ? ? ? ? ? ? ? ? remove repo

? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? if (url.startsWith('https://jcenter.bintray.com/') || url.startsWith('http://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

? ? ? ? }

? ? }

? ? buildscript{

? ? ? ? repositories {

? ? ? ? def ALIYUN_REPOSITORY_URL = 'https://maven.aliyun.com/repository/central'

? ? ? ? def ALIYUN_JCENTER_URL = 'https://maven.aliyun.com/repository/public'

? ? ? ? ? ? all { ArtifactRepository repo ->

? ? ? ? ? ? ? ? if(repo instanceof MavenArtifactRepository){

? ? ? ? ? ? ? ? ? ? def url = repo.url.toString()

? ? ? ? ? ? ? ? ? ? if (url.startsWith('https://repo1.maven.org/maven2') || url.startsWith('http://repo1.maven.org/maven2')) {

? ? ? ? ? ? ? ? ? ? ? ? project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_REPOSITORY_URL."

? ? ? ? ? ? ? ? ? ? ? ? remove repo

? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? ? ? if (url.startsWith('https://jcenter.bintray.com/') || url.startsWith('http://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

? ? ? ? ? ? }

? ? ? ? }

? ? }

}

以為大功告成了,結(jié)果還是遇到了幾個(gè)問(wèn)題。

1、需要把gradle中的也進(jìn)行替換,如下截圖:

2、出現(xiàn)類(lèi)似 Could not find com.github.chrisbanes:PhotoView:1.2.6 的問(wèn)題

關(guān)于此庫(kù)的介紹https://cloud.tencent.com/developer/article/1330894?原來(lái)它是來(lái)源于

所以,試著增加為,結(jié)果是可以了。

3、最怪異的問(wèn)題,一開(kāi)始使用“倉(cāng)庫(kù)服務(wù)”老是出現(xiàn)Connection refused。確定沒(méi)有使用proxy ,Android Studio重啟了也還是不行。

最終,找到了如下文件,把這四行刪除,試一下就行了,感覺(jué)是Android Studio的bug。

通過(guò)此問(wèn)題,發(fā)現(xiàn)一個(gè)簡(jiǎn)單的道理,像Android Studio也是去操作電腦文件中的配置文件,也存在操作不成功的問(wèn)題。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀(guān)點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容