Android Studio配置国内镜像源和HTTP代理
Android Studio配置国内镜像源和HTTP代理
一、配置国内镜像源/依赖库
1.1 打开项目的setting.gradle.kts文件
1.2 根据需要填入仓库地址
1.2.1 新版kotlin文件
maven { url=uri ("https://www.jitpack.io")} maven { url=uri ("https://maven.aliyun.com/repository/releases")} maven { url=uri ("https://maven.aliyun.com/repository/google")} maven { url=uri ("https://maven.aliyun.com/repository/central")} maven { url=uri ("https://maven.aliyun.com/repository/gradle-plugin")} maven { url=uri ("https://maven.aliyun.com/repository/public")}
- 示例
pluginManagement { repositories { maven { url=uri ("https://www.jitpack.io")} maven { url=uri ("https://maven.aliyun.com/repository/releases")} maven { url=uri ("https://maven.aliyun.com/repository/google")} maven { url=uri ("https://maven.aliyun.com/repository/central")} maven { url=uri ("https://maven.aliyun.com/repository/gradle-plugin")} maven { url=uri ("https://maven.aliyun.com/repository/public")} google() mavenCentral() gradlePluginPortal() } } dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { maven { url=uri ("https://www.jitpack.io")} maven { url=uri ("https://maven.aliyun.com/repository/releases")} maven { url=uri ("https://maven.aliyun.com/repository/google")} maven { url=uri ("https://maven.aliyun.com/repository/central")} maven { url=uri ("https://maven.aliyun.com/repository/gradle-plugin")} maven { url=uri ("https://maven.aliyun.com/repository/public")} google() mavenCentral() } } rootProject.name = "HelloWorld" include(":app")
1.2.2 旧式gradle文件
maven { url "https://jitpack.io" } maven { url 'https://maven.aliyun.com/repository/releases' } maven { url 'https://maven.aliyun.com/repository/jcenter' } maven { url 'https://maven.aliyun.com/repository/google' } maven { url 'https://maven.aliyun.com/repository/central' } maven { url 'https://maven.aliyun.com/repository/gradle-plugin' } maven { url 'https://maven.aliyun.com/repository/public' }
- 示例:
pluginManagement { repositories { maven { url "https://jitpack.io" } maven { url 'https://maven.aliyun.com/repository/releases' } maven { url 'https://maven.aliyun.com/repository/jcenter' } maven { url 'https://maven.aliyun.com/repository/google' } maven { url 'https://maven.aliyun.com/repository/central' } maven { url 'https://maven.aliyun.com/repository/gradle-plugin' } maven { url 'https://maven.aliyun.com/repository/public' } google() mavenCentral() gradlePluginPortal() } } dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { maven { url "https://jitpack.io" } maven { url 'https://maven.aliyun.com/repository/releases' } maven { url 'https://maven.aliyun.com/repository/jcenter' } maven { url 'https://maven.aliyun.com/repository/google' } maven { url 'https://maven.aliyun.com/repository/central' } maven { url 'https://maven.aliyun.com/repository/gradle-plugin' } maven { url 'https://maven.aliyun.com/repository/public' } google() mavenCentral() } } rootProject.name = "EasyUtils" include ':app'
1.3 点击“Sync Now”按钮,同步Gradle配置
1.4 注意事项
- pluginManagement和dependencyResolutionManagement里面的repositories都需要填写
- 不同的gradle文件的url格式不一样
二、配置HTTP代理
1.1 代理服务器的作用
- 内容缓存:缓存经常访问的网页和数据,当再次访问时可以直接从代理服务器获取,加快访问速度。
- 绕过限制:某些国外源在国内访问的速度极慢,通过代理可以绕过限制,实现跨地域访问。
- 安全性:匿名浏览,数据加密
1.2 国内常用的代理服务器
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.3 步骤
-
打开左上角File ==> setting ==> HTTP Proxy
-
然后填入镜像地址
腾讯: https://mirrors.cloud.tencent.com/AndroidSDK/ 阿里: https://mirrors.aliyun.com/android.googlesource.com/
-
Apply ==> OK
三、可能遇到的问题
问题1
Plugin [id: ‘com.android.application‘, version: ‘x.x.x‘, apply: false] was not found ......
解决办法
-
- 示例:
文章版权声明:除非注明,否则均为主机测评原创文章,转载或复制请以超链接形式并注明出处。