Android Studio Sync 同步慢的问题

为什么同步慢

当你 Sync Project with Gradle File 是可能回下载一些 arr jar依赖包。而 Android Studio 默认是会去国外服务器仓库下载这些包。

解决办法

  1. 翻 墙
  2. 使用阿里云Maven中央仓库

Android Studio 内配置阿里云云效 Maven

关于我的灰色历史:
因为我现在使用 Unity开发 。之前一直在用国外仓库,因为我电脑没有VPNFQ软件,打包一个四五百兆的工程包,足足花了我四五小时。没办法,就让项目组的项目经理帮我打包。速度是真的要命。后来用国内的仓库速度简直不知道快了多少。

所以希望这篇博客可以帮助大家,少采坑,如果那里写错了也希望大家激励评论,谢谢。

所以我就简单介绍我是怎么用Unity 导出项目在AndroidStudio配置国内仓库。

首先我们要在C:\Users\admin\.gradle新建一个文件 init.gradle

allprojects {
repositories {
def ALIYUN_REPOSITORY_URL = 'http://maven.aliyun.com/nexus/content/groups/public'
def ALIYUN_JCENTER_URL = 'http://maven.aliyun.com/nexus/content/repositories/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 {
allowInsecureProtocol = true
url ALIYUN_REPOSITORY_URL
url ALIYUN_JCENTER_URL
}
}
}

然后在我们的项目内找到build.gradle文件

google() 替换成阿里Maven对应的仓库maven {url "https://maven.aliyun.com/repository/google"}

jcenter()替换成阿里Maven对应的仓库maven {url "https://maven.aliyun.com/repository/public"}

最后去掉这些代码 maven {url "https://maven.google.com"}

点击Android Studio右上角的Sync按钮。

阿里云仓库地址:

仓库名称
阿里云仓库地址
阿里云仓库地址(老版)
源地址
central
https://maven.aliyun.com/repository/central
https://maven.aliyun.com/nexus/content/repositories/central
https://repo1.maven.org/maven2/
jcenter
https://maven.aliyun.com/repository/public
https://maven.aliyun.com/nexus/content/repositories/jcenter
http://jcenter.bintray.com/
public
https://maven.aliyun.com/repository/public
https://maven.aliyun.com/nexus/content/groups/public
central仓和jcenter仓的聚合仓
google
https://maven.aliyun.com/repository/google
https://maven.aliyun.com/nexus/content/repositories/google
https://maven.google.com/
gradle-plugin
https://maven.aliyun.com/repository/gradle-plugin
https://maven.aliyun.com/nexus/content/repositories/gradle-plugin
https://plugins.gradle.org/m2/
spring
https://maven.aliyun.com/repository/spring
https://maven.aliyun.com/nexus/content/repositories/spring
http://repo.spring.io/libs-milestone/
spring-plugin
https://maven.aliyun.com/repository/spring-plugin
https://maven.aliyun.com/nexus/content/repositories/spring-plugin
http://repo.spring.io/plugins-release/
grails-core
https://maven.aliyun.com/repository/grails-core
https://maven.aliyun.com/nexus/content/repositories/grails-core
https://repo.grails.org/grails/core
apache snapshots
https://maven.aliyun.com/repository/apache-snapshots
https://maven.aliyun.com/nexus/content/repositories/apache-snapshots
https://repository.apache.org/snapshots/
posted @   镜子-眼泪  阅读(1393)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
欢迎阅读『Android Studio Sync 同步慢的问题』

喜欢请打赏

扫描二维码打赏

了解更多

点击右上角即可分享
微信分享提示