You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android Gradle使用阿里云Maven仓库时的不安全协议问题求助

解决Gradle不安全协议访问仓库报错问题

排查方向与解决步骤

1. 检查全局Gradle配置

项目内未找到阿里云Maven配置但报错提示存在,大概率是全局Gradle配置中包含相关设置:

  • 打开用户目录下的.gradle文件夹(Windows:C:\Users\<你的用户名>\.gradle;Mac/Linux:~/.gradle)
  • 查看init.gradle或gradle.properties文件,是否存在类似配置:
    repositories {
        maven { url "http://maven.aliyun.com/nexus/content/repositories/jcenter" }
    }
    
  • 优先将HTTP协议改为HTTPS:https://maven.aliyun.com/repository/jcenter;若必须保留HTTP,在该仓库配置中添加允许不安全协议的参数:
    maven { 
        url "http://maven.aliyun.com/nexus/content/repositories/jcenter"
        allowInsecureProtocol = true 
    }
    

2. 排查间接依赖的仓库引用

若全局配置无问题,可能是项目依赖的第三方库间接引用了阿里云HTTP仓库:

  • 在项目根目录执行命令,查看所有依赖的仓库来源:
    ./gradlew dependencies
    
  • 从输出中定位到请求http://maven.aliyun.com/...仓库的依赖
  • 处理方式二选一:
    • 替换该依赖为不使用HTTP仓库的版本
    • 在项目settings.gradle的dependencyResolutionManagement中添加该仓库并允许不安全协议:
      dependencyResolutionManagement {
          repositories {
              // 保留原有仓库配置
              maven { 
                  url "http://maven.aliyun.com/nexus/content/repositories/jcenter"
                  allowInsecureProtocol = true 
              }
          }
      }
      

3. 替换废弃的JCenter仓库

项目中仍在使用已停止维护的JCenter仓库,建议直接替换为阿里云HTTPS仓库或Maven Central:
修改settings.gradle中的JCenter配置:

// 替换原有的https://jcenter.bintray.com
maven { url "https://maven.aliyun.com/repository/jcenter" }

若所有依赖都能在Maven Central找到,也可直接移除JCenter,仅保留mavenCentral()

4. 全局临时允许不安全协议(不推荐)

若以上方法均无法解决,可在项目根目录的gradle.properties中添加全局配置(注意:此操作会降低所有仓库的安全性):

org.gradle.jvmargs=-Dorg.gradle.internal.http.allowInsecureProtocol=true

内容的提问来源于stack exchange,提问作者崔小杨

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.02 14:40:24