首页 > 技术文章 > Android Studio代理-build过慢以及gradle下载失败解决方案

best-hym 2020-02-02 10:01 原文

由于墙的存在,安卓开发者在使用android studio开发时,总会遇到下载库或者升级卡着不动的情况。如果有个代理镜像服务器,可以帮我们从国外下载,然后再映射到国内服务器该多好。感谢阿里,提供了镜像服务器。

让项目通过阿里云 maven jcenter 下载依赖资源

打开项目根目录下的 build.gradle(Project:项目名称一级的gradle),如下所示添加阿里 maven 库地址:

buildscript {
    
  
     repositories {
         // 添加阿里云 maven 地址
         maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
         maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' }
  
         google()
         jcenter()
      
     }
     dependencies {
         classpath 'com.android.tools.build:gradle:3.4.1'
     }
 }
  
 allprojects {
     repositories {
         // 添加阿里云 maven 地址
         maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
         maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' }
  
         google()
         jcenter()
     
         maven { url 'https://jitpack.io' }
     }
 }
  
 task clean(type: Delete) {
     delete rootProject.buildDir
 }

重新 Make Project 项目,编译时的资源下载一般就会顺畅了。

 

推荐阅读