Android Studio Gradle 更換阿里云鏡像的方法
使用 Android Studio 開發(fā)時經(jīng)常遇到編譯卡住的問題,原因是 Gradle 下載依賴資源過慢。沒辦法,有長城在,還是得換鏡像。
同樣,這是個普遍存在的問題,我們希望可以對它進行全局配置。在 .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
}
}
}
}
如只需對單個項目進行配置,可以在項目根目錄下的 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)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Android操作系統(tǒng)的架構(gòu)設(shè)計分析
這篇文章主要介紹了Android操作系統(tǒng)的架構(gòu)設(shè)計分析,Android系統(tǒng)架構(gòu)分為Linux內(nèi)核驅(qū)動、C/C ++框架、Java框架、Java應(yīng)用程序,本文分別講解了它的作用,需要的朋友可以參考下2015-06-06
使用Android Studio檢測內(nèi)存泄露(LeakCanary)
本篇文章主要介紹了用Android Studio檢測內(nèi)存泄露的問題的解決方法,Android Studio在為我們提供了良好的編碼體驗的同時,也提供了許多對App性能分析的工具,下面我們一起來了解一下。2016-12-12
Android時間對話框TimePickerDialog詳解
這篇文章主要為大家詳細介紹了Android時間對話框TimePickerDialog的相關(guān)資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-02-02
在Android中創(chuàng)建菜單項Menu以及獲取手機分辨率的解決方法
本篇文章小編為大家介紹,在Android中創(chuàng)建菜單項Menu以及獲取手機分辨率的解決方法。需要的朋友參考下2013-04-04

