国内如何提高android依赖jar包的下载速度

这里只是个转载哈,怕以后用的时候找不到,自己记录下。
非常感谢原文作者让我们提高了很多效率哈哈
https://zhuanlan.zhihu.com/p/26019083

很多人用Android Studio,最不爽的就是下载包依赖非常的缓慢。这是因为国内bintray网站访问速度很慢。谢谢阿里云,给我们提供了bintray jcenter mirror。如果想用阿里云的jcenter加速,请在用户目录/.gradle里放上下面的配置文件init.gradle,即可自动将依赖改为从阿里云下载。

gradle.projectsLoaded {
    rootProject.allprojects {
        buildscript {
            repositories {
                def REPOSITORY_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')
                            || url.startsWith('https://jcenter.bintray.com/')) {
                            project.logger.lifecycle "Repository ${repo.url} replaced by $REPOSITORY_URL."
                            println("buildscript ${repo.url} replaced by $REPOSITORY_URL.")
                            remove repo
                        }
                    }
                }
                jcenter {
                    url REPOSITORY_URL
                }
            }
        }
        repositories {
            def REPOSITORY_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')
                        || url.startsWith('https://jcenter.bintray.com/')) {
                        project.logger.lifecycle "Repository ${repo.url} replaced by $REPOSITORY_URL."
                        println("allprojects ${repo.url} replaced by $REPOSITORY_URL.")
                        remove repo
                    }
                }
            }
            jcenter {
                url REPOSITORY_URL
            }
        }
    }
}

好了OK了:)
再次感谢原文作者

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值