Android Studio Gradle 更換阿里云鏡像的方法
使用 Android Studio 開發時經常遇到編譯卡住的問題,原因是 Gradle 下載依賴資源過慢。沒辦法,有長城在,還是得換鏡像。
同樣,這是個普遍存在的問題,我們希望可以對它進行全局配置。在 .gradle (路徑參考 C:Usersusername.gradle )目錄下新增 init.gradle 文件,內容如下:
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’ }
搞定,下載速度飛起~
到此這篇關于Android Studio Gradle 更換阿里云鏡像的方法的文章就介紹到這了,更多相關Android Studio Gradle阿里云內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!
相關文章:
1. 基于javaweb+jsp實現企業車輛管理系統2. 怎樣才能用js生成xmldom對象,并且在firefox中也實現xml數據島?3. 利用ajax+php實現商品價格計算4. ASP.Net MVC利用NPOI導入導出Excel的示例代碼5. jstl 字符串處理函數6. JSP動態網頁開發原理詳解7. PHP中為什么使用file_get_contents("php://input")接收微信通知8. .Net core Blazor+自定義日志提供器實現實時日志查看器的原理解析9. IOS蘋果AppStore內購付款的服務器端php驗證方法(使用thinkphp)10. XML CDATA是什么?
