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