赞
踩
很多人在使用Android Studio的时候,刚打开或者新建项目都会很慢,因为它要经过Sync和Build,而app运行需要Gradle进行编译,所以要通过Sync下载需要的内容。Android Studio默认是通过google外网下载的,所以下载会非常的慢,一般会需要4到6个小时左右(有些可能更久),这要是在写项目的话,那也太浪费时间了,黄花菜都要凉了呀。所以为了节省时间,提高开发效率,我们就需要把外网改为国内的进行下载。下面就来说一下我是如何解决的。
1、找到项目中的build.gradle文件进行修改,主要是修改buildscript和allprojects下repositories中的内容。
- // Top-level build file where you can add configuration options common to all sub-projects/modules.
-
- buildscript {
- repositories {
- // jcenter()
- // maven {
- // url 'https://maven.google.com/'
- // name 'Google'
- // }
- // google()
-
- //修改: 添加阿里云 maven 地址
- maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
- maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' }
- google()
- }
- dependencies {
- classpath 'com.android.tools.build:gradle:3.5.0'
-
- // NOTE: Do not place your application dependencies here; they belong
- // in the individual module build.gradle files
- }
- }
-
- allprojects {
- repositories {
- // jcenter()
- // maven {
- // url 'https://maven.google.com/'
- // name 'Google'
- // }
- // google()
- // 修改:添加阿里云 maven 地址
- maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
- maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' }
- google()
- }
- }
-
- task clean(type: Delete) {
- delete rootProject.buildDir
- }

2、改完之后重新启动Android Studio即可(如果之前gradle已经下载了一半的,建议删除掉,然后再修改重启,删除的文件(.gradle文件夹)如下图所示【文件路径一般是C:\Users\Admin】),重启后Sync和Build就会非常快,几分钟甚至一分钟都不到就可以了。
好了,今天我就分享到这里,see you...
ps:若出现问题,可参考maven地址
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。