当前位置:   article > 正文

解决Android Studio Gradle Build过慢的问题_android studio gradle下载慢

android studio gradle下载慢

很多人在使用Android Studio的时候,刚打开或者新建项目都会很慢,因为它要经过Sync和Build,而app运行需要Gradle进行编译,所以要通过Sync下载需要的内容。Android Studio默认是通过google外网下载的,所以下载会非常的慢,一般会需要4到6个小时左右(有些可能更久),这要是在写项目的话,那也太浪费时间了,黄花菜都要凉了呀。所以为了节省时间,提高开发效率,我们就需要把外网改为国内的进行下载。下面就来说一下我是如何解决的。

1、找到项目中的build.gradle文件进行修改,主要是修改buildscriptallprojectsrepositories中的内容。

  1. // Top-level build file where you can add configuration options common to all sub-projects/modules.
  2. buildscript {
  3. repositories {
  4. // jcenter()
  5. // maven {
  6. // url 'https://maven.google.com/'
  7. // name 'Google'
  8. // }
  9. // google()
  10. //修改: 添加阿里云 maven 地址
  11. maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
  12. maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' }
  13. google()
  14. }
  15. dependencies {
  16. classpath 'com.android.tools.build:gradle:3.5.0'
  17. // NOTE: Do not place your application dependencies here; they belong
  18. // in the individual module build.gradle files
  19. }
  20. }
  21. allprojects {
  22. repositories {
  23. // jcenter()
  24. // maven {
  25. // url 'https://maven.google.com/'
  26. // name 'Google'
  27. // }
  28. // google()
  29. // 修改:添加阿里云 maven 地址
  30. maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
  31. maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' }
  32. google()
  33. }
  34. }
  35. task clean(type: Delete) {
  36. delete rootProject.buildDir
  37. }

2、改完之后重新启动Android Studio即可(如果之前gradle已经下载了一半的,建议删除掉,然后再修改重启,删除的文件(.gradle文件夹)如下图所示【文件路径一般是C:\Users\Admin】),重启后Sync和Build就会非常快,几分钟甚至一分钟都不到就可以了。

好了,今天我就分享到这里,see you...

ps:若出现问题,可参考maven地址

 

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

闽ICP备14008679号