Android studio 全局設(shè)置阿里鏡像
本文原創(chuàng),轉(zhuǎn)載請(qǐng)注明出處线召。歡迎關(guān)注我的 簡(jiǎn)書(shū)帝际。
安利一波我寫(xiě)的開(kāi)發(fā)框架:MyScFrame喜歡的話就給個(gè)Star
平時(shí)安卓項(xiàng)目編譯較慢餐禁,其中一個(gè)原因就是要下載依賴資源包比較慢诵肛。為了解決這個(gè)問(wèn)題,可以配置阿里云鏡像箱蟆,加速下載
關(guān)于阿里云的鏡像可以查看他們的阿里云云效 Maven或者是公共代理庫(kù)
常規(guī)做法
以前拿到項(xiàng)目或者是網(wǎng)上的開(kāi)源庫(kù),覺(jué)得下載依賴包太慢的時(shí)候,我們都是直接在項(xiàng)目根目錄下的build.gradle中添加阿里的鏡像,這樣雖然說(shuō)能解決下載依賴包慢的問(wèn)題,但是每次都這么搞一次也是很費(fèi)事
buildscript {
repositories {
// 改為阿里云的鏡像地址
maven { url 'https://maven.aliyun.com/repository/central' }
maven { url 'https://maven.aliyun.com/repository/jcenter' }
maven { url 'https://maven.aliyun.com/repository/google' }
maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
maven { url 'https://maven.aliyun.com/repository/public' }
// google()
// jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.0.0'
}
}
allprojects {
repositories {
// 改為阿里云的鏡像地址
maven { url 'https://maven.aliyun.com/repository/central' }
maven { url 'https://maven.aliyun.com/repository/jcenter' }
maven { url 'https://maven.aliyun.com/repository/google' }
maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
maven { url 'https://maven.aliyun.com/repository/public' }
// google()
// jcenter()
}
}
全局配置(對(duì)所有項(xiàng)目生效)
先在$GRADLE_USER_HOME/.gradle
目錄下創(chuàng)建一個(gè)叫init.gradle的文件
然后輸入以下內(nèi)容
def repoConfig = {
all { ArtifactRepository repo ->
if (repo instanceof MavenArtifactRepository) {
def url = repo.url.toString()
if (url.contains('repo1.maven.org/maven2') || url.contains('jcenter.bintray.com')) {
println "gradle init: (${repo.name}: ${repo.url}) removed"
remove repo
}
}
}
maven { url 'https://maven.aliyun.com/repository/central' }
maven { url 'https://maven.aliyun.com/repository/jcenter' }
maven { url 'https://maven.aliyun.com/repository/google' }
maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
maven { url 'https://maven.aliyun.com/repository/public' }
}
allprojects {
buildscript {
repositories repoConfig
}
repositories repoConfig
}