【转】Android stuido新建Project Gradle:Download https:// jcenter.bintray.com/ 下载慢,超时问题解决方法

https://blog.youkuaiyun.com/mars314/article/details/81910789

 

方法一:

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/'}
    }
}

亲测,此方法有效。

 

方法二:

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

阿里的仓库地址:http://maven.aliyun.com/nexus/content/groups/public/
OSChina的仓库地址:http://maven.oschina.net/content/groups/public/
 


buildscript {
    repositories {
        maven{url"https://maven.google.com"}

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

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.3'

    }
}

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

    gradle.projectsEvaluated {
        tasks.withType(JavaCompile) {
            options.encoding = "UTF-8"
        }
    }
}

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

阿里的这个有效。

方法三:
手机开热点,电脑连接上手机热点,用手机完成;

亲测有效。

 

方法四:
万能方法,此方法怎么着都行,离线gradle都成。下载https://download.youkuaiyun.com/download/mars314/10618153覆盖你的gradle,可解决无法下jcenter缓慢超时问题!

 

总结:原地址:https:// jcenter.bintray.com/一亘有一次下载成功了,以后都会成功。修改协议:后续工程也得修改协议/
------------------

 

### 解决方案概述 对于遇到 `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、付费专栏及课程。

余额充值