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. 利用CSS3新特性創(chuàng)建透明邊框三角2. html清除浮動的6種方法示例3. CSS3實例分享之多重背景的實現(xiàn)(Multiple backgrounds)4. vue實現(xiàn)將自己網(wǎng)站(h5鏈接)分享到微信中形成小卡片的超詳細教程5. 不要在HTML中濫用div6. 使用css實現(xiàn)全兼容tooltip提示框7. 詳解CSS偽元素的妙用單標簽之美8. JavaScript數(shù)據(jù)類型對函數(shù)式編程的影響示例解析9. CSS代碼檢查工具stylelint的使用方法詳解10. Vue3使用JSX的方法實例(筆記自用)
