一、Gradle/Maven配置国内镜像源
配置方式有仅对单个项目生效和对所有项目生效两种方式 对单个项目生效
1.打开Android Studio工程文件,找到build.gradle
2.使用文本编辑器打开,默认格式如下:
buildscript { repositories { google() jcenter() } dependencies { classpath 'com.android.tools.build3.5.1' } } allprojects { repositories { google() jcenter() } } task clean(type: Delete) { delete rootProject.buildDir }3.修改为以下内容:
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.build3.5.1' } } 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 }对所有项目生效
C:Usersxxx.gradle2.新建文件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.东软信息学院
mirrors.neusoft.edu.cn 端口:802.北京化工大学
ubuntu.buct.edu.cn/ubuntu.buct.cn 端口:803.中国科学院开源协会
mirrors.opencas.cn (mirrors.opencas.org/mirrors.opencas.ac.cn) 端口:804.上海GDG镜像服务器
sdk.gdgshanghai.com 端口:80005.电子科技大学
mirrors.dormforce.net 端口:80配置步骤:
-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即可
审核编辑:汤梓红
全部0条评论
快来发表一下你的评论吧 !