当前位置:   article > 正文

Android Studio配置阿里云镜像地址,加速依赖资源下载_android studio 阿里云

android studio 阿里云

背景:

     平时安卓项目编译较慢,其中一个原因就是要下载依赖资源包比较慢。为了解决这个问题,可以配置阿里云镜像,加速下载。

配置方法:

一、全局配置(对所有项目生效)

在"用户目录/.gradle"目录下新增文件init.gradle.

  • 目录截图样例

  1. allprojects{
  2. repositories {
  3. def ALIYUN_REPOSITORY_URL = 'http://maven.aliyun.com/nexus/content/groups/public'
  4. def ALIYUN_JCENTER_URL = 'http://maven.aliyun.com/nexus/content/repositories/jcenter'
  5. all { ArtifactRepository repo ->
  6. if(repo instanceof MavenArtifactRepository){
  7. def url = repo.url.toString()
  8. if (url.startsWith('https://repo1.maven.org/maven2') || url.startsWith('http://repo1.maven.org/maven2')) {
  9. project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_REPOSITORY_URL."
  10. remove repo
  11. }
  12. if (url.startsWith('https://jcenter.bintray.com/') || url.startsWith('http://jcenter.bintray.com/')) {
  13. project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_JCENTER_URL."
  14. remove repo
  15. }
  16. }
  17. }
  18. maven {
  19. url ALIYUN_REPOSITORY_URL
  20. url ALIYUN_JCENTER_URL
  21. }
  22. }
  23. buildscript{
  24. repositories {
  25. def ALIYUN_REPOSITORY_URL = 'http://maven.aliyun.com/nexus/content/groups/public'
  26. def ALIYUN_JCENTER_URL = 'http://maven.aliyun.com/nexus/content/repositories/jcenter'
  27. all { ArtifactRepository repo ->
  28. if(repo instanceof MavenArtifactRepository){
  29. def url = repo.url.toString()
  30. if (url.startsWith('https://repo1.maven.org/maven2') || url.startsWith('http://repo1.maven.org/maven2')) {
  31. project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_REPOSITORY_URL."
  32. remove repo
  33. }
  34. if (url.startsWith('https://jcenter.bintray.com/') || url.startsWith('http://jcenter.bintray.com/')) {
  35. project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_JCENTER_URL."
  36. remove repo
  37. }
  38. }
  39. }
  40. maven {
  41. url ALIYUN_REPOSITORY_URL
  42. url ALIYUN_JCENTER_URL
  43. }
  44. }
  45. }
  46. }

二、对指定项目配置

修改项目根目录下的build.gradle文件内容,增加如下信息:

  1. maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
  2. maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' }
  3. maven { url 'http://maven.aliyun.com/nexus/content/repositories/google' }
  4. maven { url 'http://maven.aliyun.com/nexus/content/repositories/gradle-plugin' }

完整样例:

  1. buildscript {
  2. repositories {
  3. maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
  4. maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' }
  5. maven { url 'http://maven.aliyun.com/nexus/content/repositories/google' }
  6. maven { url 'http://maven.aliyun.com/nexus/content/repositories/gradle-plugin' }
  7. }
  8. dependencies {
  9. classpath 'com.android.tools.build:gradle:3.2.1'
  10. }
  11. }
  12. allprojects {
  13. repositories {
  14. maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
  15. maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' }
  16. maven { url 'http://maven.aliyun.com/nexus/content/repositories/google' }
  17. maven { url 'http://maven.aliyun.com/nexus/content/repositories/gradle-plugin' }
  18. }
  19. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/99602
推荐阅读
相关标签
  

闽ICP备14008679号