Android Studio Gradle 更換阿里云鏡像的方法
使用 Android Studio 開(kāi)發(fā)時(shí)經(jīng)常遇到編譯卡住的問(wèn)題,原因是 Gradle 下載依賴資源過(guò)慢。沒(méi)辦法,有長(zhǎng)城在,還是得換鏡像。
同樣,這是個(gè)普遍存在的問(wèn)題,我們希望可以對(duì)它進(jìn)行全局配置。在 .gradle (路徑參考 C:\Users\username\.gradle )目錄下新增 init.gradle 文件,內(nèi)容如下:
allprojects{ repositories { def ALIYUN_REPOSITORY_URL = 'http://maven.aliyun.com/nexus/content/groups/public' def ALIYUN_JCENTER_URL = 'http://maven.aliyun.com/nexus/content/repositories/jcenter' 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 = 'http://maven.aliyun.com/nexus/content/groups/public' def ALIYUN_JCENTER_URL = 'http://maven.aliyun.com/nexus/content/repositories/jcenter' 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 } } } }
如只需對(duì)單個(gè)項(xiàng)目進(jìn)行配置,可以在項(xiàng)目根目錄下的 build.gradle 文件中添加如下代碼:
maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' } maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' } maven { url 'http://maven.aliyun.com/nexus/content/repositories/google' } maven { url 'http://maven.aliyun.com/nexus/content/repositories/gradle-plugin' }
搞定,下載速度飛起~
到此這篇關(guān)于Android Studio Gradle 更換阿里云鏡像的方法的文章就介紹到這了,更多相關(guān)Android Studio Gradle阿里云內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
android全屏去掉title欄的多種實(shí)現(xiàn)方法
android全屏去掉title欄包括以下幾個(gè)部分:實(shí)現(xiàn)應(yīng)用中的所有activity都全屏/實(shí)現(xiàn)單個(gè)activity全屏/實(shí)現(xiàn)單個(gè)activity去掉title欄/自定義標(biāo)題內(nèi)容/自定義標(biāo)題布局等等感興趣的可參考下啊2013-02-02android IntentService實(shí)現(xiàn)原理及內(nèi)部代碼分享
android IntentService實(shí)現(xiàn)原理及內(nèi)部代碼分享,需要的朋友可以參考一下2013-06-06Android編程之監(jiān)聽(tīng)器用法實(shí)例分析
這篇文章主要介紹了Android編程之監(jiān)聽(tīng)器用法,結(jié)合實(shí)例形式較為詳細(xì)的分析了Android監(jiān)聽(tīng)器的功能及針對(duì)短信的監(jiān)聽(tīng)與響應(yīng)操作技巧,需要的朋友可以參考下2016-01-01Android實(shí)現(xiàn)QQ側(cè)滑(刪除、置頂?shù)?功能
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)QQ側(cè)滑刪除、置頂?shù)裙δ埽哂幸欢ǖ膮⒖純r(jià)值,感興趣的小伙伴們可以參考一下2017-12-12Android自定義水波紋動(dòng)畫(huà)Layout實(shí)例代碼
這篇文章主要介紹了Android自定義水波紋動(dòng)畫(huà)Layout的實(shí)例代碼,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-11-11Android Studio生成 Flutter 模板代碼技巧詳解
這篇文章主要為大家介紹了Android Studio生成 Flutter 模板代碼技巧詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-10-10Android通過(guò)ksoap2傳遞復(fù)雜數(shù)據(jù)類(lèi)型及CXF發(fā)布的webservice詳細(xì)介紹
這篇文章主要介紹了 Android通過(guò)ksoap2傳遞復(fù)雜數(shù)據(jù)類(lèi)型詳細(xì)介紹的相關(guān)資料,需要的朋友可以參考下2017-02-02一文搞懂Android RecyclerView點(diǎn)擊展開(kāi)、折疊效果的實(shí)現(xiàn)代碼
雖然在日常開(kāi)發(fā)中已經(jīng)多次接觸過(guò)RecycleView,但也只是用到其最基本的功能,并沒(méi)有深入研究其他內(nèi)容。接下來(lái)將抽出時(shí)間去了解RecycleView的相關(guān)內(nèi)容,這篇文章主要是介紹Android RecyclerView點(diǎn)擊展開(kāi)、折疊效果的實(shí)現(xiàn)方式,一起看看吧2021-06-06Android PopupWindow被輸入法彈上去之后無(wú)法恢復(fù)原位的解決辦法
這篇文章主要介紹了Android PopupWindow被輸入法彈上去之后無(wú)法恢復(fù)原位的解決辦法,需要的朋友可以參考下2016-12-12