美文网首页Android开发
jcenter 下载慢、超时问题解决

jcenter 下载慢、超时问题解决

作者: Enowr | 来源:发表于2017-03-13 09:56 被阅读6568次

在使用 Gradle 构建工程时,jcenter 下载慢、超时的解决方法。

方法一:

https 改成 http 协议下载,修改项目根目录下 build.gradle 文件:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
//        jcenter()
        jcenter(){url 'http://jcenter.bintray.com/'}
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
//        jcenter()
        jcenter(){url 'http://jcenter.bintray.com/'}
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

方法二:

切换到国内的Maven镜像仓库。
修改项目根目录下 build.gradle 文件,将 jcenter() 或者 mavenCentral() 替换掉即可。

repositories {
    maven{ url 'http://maven.aliyun.com/nexus/content/repositories/central/'}
}

或全局修改,USER_HOME/.gradle/ 文件夹下新建 init.gradle 文件,添加如下内容:

allprojects{
    repositories {
        def REPOSITORY_URL = 'http://maven.aliyun.com/nexus/content/repositories/central/'
        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."
                    remove repo
                }
            }
        }
        maven {
            url REPOSITORY_URL
        }
    }
}

init.gradle 文件其实是 Gradle 的初始化脚本 (Initialization Scripts),也是运行时的全局配置。

相关文章

  • jcenter 下载慢、超时问题解决

    在使用 Gradle 构建工程时,jcenter 下载慢、超时的解决方法。 方法一: https 改成 http ...

  • android镜像源

    问题 依赖下载慢或失败 解决方案 替换google()和jcenter()源google()jcenter()替换...

  • 解决JCenter下载慢

    修改项目根目录下 build.gradle 中内容如下: buildscript { repositories ...

  • 2020-07-24 Received close_notify

    问题存在原因:这是Android编译错误,jcenter里面的东西下载不了引起的。问题解决:在项目的build.g...

  • pip 下载慢/失败

    pip安装遇到下载速度特别慢甚至请求超时错误的“.ReadTimeoutError: HTTPSConnectio...

  • Goproxy 解决 go get 下载超时

    问题:go get 超时,下载速度慢 使用 goproxy项目地址: Github[https://github....

  • Docker 镜像加速

    在制作Docker 镜像时,很有可能会遇到下载速度慢,超时等情况,这种情况其实和Anaconda 超时的原因一样,...

  • Maven下载速度缓慢

    首次用maven时idea会下载大量jar包会导致进程非常慢甚至超时下载 解决:将idea自带的maven替换,自...

  • jcenter下载太慢

    一、记录背景 最近下载公司一个公共组件库,编译的时候,总是有好几个库下载不下来,阻挡了我生成aar的步伐,等待加载...

  • Android Studio引用远程仓库(JCenter)下载慢

    1 方法一: 使用开源中国的maven库阿里云的(速度巨快) 替换项目根目录下build.gradle中 改为 2...

网友评论

    本文标题:jcenter 下载慢、超时问题解决

    本文链接:https://www.haomeiwen.com/subject/vrkfnttx.html