赞
踩
配置方式有仅对单个项目生效和对所有项目生效两种方式
对单个项目生效
1.打开Android Studio工程文件,找到build.gradle
2.使用文本编辑器打开,默认格式如下:
- // Top-level build file where you can add configuration options common to all sub-projects/modules.
-
- buildscript {
- repositories {
- google()
- jcenter()
-
- }
- dependencies {
- classpath 'com.android.tools.build:gradle:3.5.1'
-
- // NOTE: Do not place your application dependencies here; they belong
- // in the individual module build.gradle files
- }
- }
-
- allprojects {
- repositories {
- google()
- jcenter()
-
- }
- }
-
- task clean(type: Delete) {
- delete rootProject.buildDir
- }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
3.修改为以下内容:
- // Top-level build file where you can add configuration options common to all sub-projects/modules.
-
- buildscript {
- repositories {
- maven {
- url 'https://maven.aliyun.com/repository/google'
- }
- maven {
- url 'https://maven.aliyun.com/repository/public'
- }
- maven {
- url 'https://maven.aliyun.com/repository/jcenter'
- }
- }
- dependencies {
- classpath 'com.android.tools.build:gradle:3.5.1'
-
-
- // NOTE: Do not place your application dependencies here; they belong
- // in the individual module build.gradle files
- }
- }
-
- allprojects {
- repositories {
- maven {
- url 'https://maven.aliyun.com/repository/google'
- }
- maven {
- url 'https://maven.aliyun.com/repository/public'
- }
- maven {
- url 'https://maven.aliyun.com/repository/jcenter'
- }
- }
- }
-
- task clean(type: Delete) {
- delete rootProject.buildDir
- }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
对所有项目生效
1.打开系统用户的Gradle配置目录:C:\Users\xxx.gradle
2.新建文件init.gradle(注意文件后缀名为gradle)
- allprojects{
- repositories {
- def ALIYUN_REPOSITORY_URL = 'https://maven.aliyun.com/repository/public'
- def ALIYUN_JCENTER_URL = 'https://maven.aliyun.com/repository/jcenter'
- all { ArtifactRepository repo ->
- if (repo instanceof MavenArtifactRepository){
- def url = repo.url.toString()
- if (url.startsWith('https://repo1.maven.org/maven2')) {
- project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_REPOSITORY_URL."
- remove repo
- }
- if (url.startsWith('https://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
- }
- }
- }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
第一种 直接配置国内镜像源
推荐几个国内镜像源地址:
1、东软信息学院
mirrors.neusoft.edu.cn 端口:80
2、北京化工大学
ubuntu.buct.edu.cn/ubuntu.buct.cn 端口:80
3、中国科学院开源协会
mirrors.opencas.cn (mirrors.opencas.org/mirrors.opencas.ac.cn) 端口:80
4、上海GDG镜像服务器
sdk.gdgshanghai.com 端口:8000
5、电子科技大学
mirrors.dormforce.net 端口:80
下面给出配置步骤:
1.打开File -> setting -> Appearance & Behavior-> System Settings -> HTTP Proxy
2.点击Manual proxy configuration,选中HTTP,在Host name中输入地址,并在Port number中输入端口号
第二种 利用host配置国内镜像源
1.在C盘的C:\Windows\System32\drivers\etc路径下找到hosts文件,并用记事本打开(或者用notepad++)
2.打开多个地点Ping服务器,网站测速(http://ping.chinaz.com/) - 站长工具该网站对dl.google.com进行ping检测,得到可以用的IP地址,并将其添加到hosts文件末尾
3.配置Android Studio
找到Android Studio安装目录,进入bin文件夹找到studio64.exe.vmoptions,并用记事本打开(或者用notepad++)
4.在studio64.exe.vmoptions末尾添加以下配置:
- -Djava.net.preferIPv4Stack=true
- -Didea.updates.url=http://dl.google.com/android/studio/patches/updates.xml
- -Didea.patches.url=http://dl.google.com/android/studio/patches/
5.在Android studio中打开File -> setting -> Appearance & Behavior-> System Settings -> HTTP Proxy,选中No proxy即可
关注我获取更多知识或者投稿
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。