Android Studio Gradle 更換阿里云鏡像的方法
使用 Android Studio 開發(fā)時經(jīng)常遇到編譯卡住的問題,原因是 Gradle 下載依賴資源過慢。沒辦法,有長城在,還是得換鏡像。
同樣,這是個普遍存在的問題,我們希望可以對它進行全局配置。在 .gradle (路徑參考 C:Usersusername.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_URLurl ALIYUN_JCENTER_URL } } }}
如只需對單個項目進行配置,可以在項目根目錄下的 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)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. Python使用oslo.vmware管理ESXI虛擬機的示例參考2. Jsp servlet驗證碼工具類分享3. .NET6打包部署到Windows Service的全過程4. python GUI庫圖形界面開發(fā)之PyQt5滑塊條控件QSlider詳細使用方法與實例5. IntelliJ IDEA 好用插件之a(chǎn)nalyze inspect code詳解6. JetBrains IntelliJ IDEA 配置優(yōu)化技巧7. idea2020.1無法自動加載maven依賴的jar包問題及解決方法8. PHP程序員簡單的開展服務(wù)治理架構(gòu)操作詳解(一)9. vue項目中使用bpmn為節(jié)點添加顏色的方法10. 解決idea update project 更新選項消失的問題
