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: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 } } }}
如只需對(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)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. React實(shí)現(xiàn)一個(gè)倒計(jì)時(shí)hook組件實(shí)戰(zhàn)示例2. WMLScript的語(yǔ)法基礎(chǔ)3. CSS3實(shí)例分享之多重背景的實(shí)現(xiàn)(Multiple backgrounds)4. XML入門(mén)的常見(jiàn)問(wèn)題(三)5. JavaScript中顏色模型的基礎(chǔ)知識(shí)與應(yīng)用詳解6. 不要在HTML中濫用div7. XML 非法字符(轉(zhuǎn)義字符)8. el-input無(wú)法輸入的問(wèn)題和表單驗(yàn)證失敗問(wèn)題解決9. 前端html+css實(shí)現(xiàn)動(dòng)態(tài)生日快樂(lè)代碼10. XML 增、刪、改和查示例
