Gradle:Download https:// jcenter.bintray.com/ 下载缓慢解决方法

本文介绍了解决Gradle依赖下载慢或失败的问题,提供了两种解决方案:一是切换到阿里云或OSChina的镜像仓库;二是更换本地Gradle配置。文中详细展示了如何修改build.gradle文件来实现镜像源的切换。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

方案一:切换镜像仓库

原文地址
阿里的仓库地址(亲测有效):http://maven.aliyun.com/nexus/content/groups/public/
OSChina的仓库地址:http://maven.oschina.net/content/groups/public/

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

buildscript {
    repositories {
        maven{ url 'http://maven.aliyun.com/nexus/content/repositories/central/'}
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'

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

allprojects {
    repositories {
        maven{ url 'http://maven.aliyun.com/nexus/content/repositories/central/'}
        google()
        jcenter()
    }
}

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

以上方法下载有时会下载不了,替换后如下:

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

buildscript {
    repositories {
//        maven{ url 'http://maven.aliyun.com/nexus/content/repositories/central/'}
//        maven()
        maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
        maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' }
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'

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

allprojects {
    repositories {
//        maven{ url 'http://maven.aliyun.com/nexus/content/repositories/central/'}
//        maven()
        maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
        maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' }
        google()
        jcenter()
    }
}

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

方案二:更换本地Gradle

原文地址
未经测试,自行查阅原文 O(∩_∩)O~~

### 解决方案概述 对于遇到 `PKIX path building failed` 错误的情况,尤其是在访问像 JCenterBintray 这样的远程仓库时,通常是因为 Java 安全框架未能找到有效的认证路径来验证服务器提供的 SSL/TLS 证书。这可能由于本地 JDK/JRE 的受信证书库缺少必要的 CA 证书。 为了修复此问题并成功连接至 jcenter.bintray.com,可以采取以下措施: #### 更新JDK自带CA证书库 确保使用最新版本的 JDK 可能会解决问题,因为较新的 JDK 版本包含了更多更新过的 CA 证书。如果已经是最新的 JDK,则考虑手动导入所需的 CA 证书到当前使用的 JDK 中[^2]。 ```bash cd $JAVA_HOME/jre/lib/security/ keytool -importcert -alias bintray -file /path/to/bintray.pem -keystore cacerts ``` 默认密码通常是 `changeit`. #### 修改Gradle配置文件以忽略SSL验证(不推荐) 虽然可以通过设置 Gradle 来跳过 SSL 验证从而绕过这个问题,但这不是一个安全的做法,并且可能会使应用程序面临中间人攻击的风险。因此这种方法仅作为临时解决方案,在生产环境中应避免这样做[^1]. ```groovy // build.gradle or settings.gradle systemProp.http.strictssl=false ``` #### 使用HTTPS代理或自定义TrustManager(高级选项) 另一种方法是在构建过程中通过 HTTPS 代理转发请求或将特定站点加入白名单的方式处理;也可以编写自定义 TrustManager 类来自行管理哪些主机名是可以信任的。不过这些都需要更深入的技术背景以及对项目安全性有充分理解的情况下实施[^4].
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值