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/


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM