android studio 同时支持http和https

报错信息:

xml 复制代码
FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'develop'.
> Could not resolve all files for configuration ':classpath'.
   > Could not download agcp-1.6.0.300.jar (com.huawei.agconnect:agcp:1.6.0.300)
      > Could not get resource 'https://developer.huawei.com/repo/com/huawei/agconnect/agcp/1.6.0.300/agcp-1.6.0.300.jar'.
         > Could not HEAD 'https://developer.huawei.com/repo/com/huawei/agconnect/agcp/1.6.0.300/agcp-1.6.0.300.jar'.
            > The server may not support the client's requested TLS protocol versions: (TLSv1.2, TLSv1.3). You may need to configure the client to allow other protocols to be used. See: https://docs.gradle.org/8.0.1/userguide/build_environment.html#gradle_system_properties
               > Remote host terminated the handshake

意思是华为这个库对于TLS protocol versions: (TLSv1.2, TLSv1.3)不支持。

这个问题是由于 Gradle 无法下载某些依赖项文件,这可能是因为服务器与客户端之间的 TLS 协议不兼容。问题出在 Android Studio 构建时尝试通过 HTTPS 下载某些文件,但由于协议版本问题(例如,服务器不支持 TLS 1.2 或 1.3),导致握手失败。

为了修复此问题,你可以尝试以下步骤:

  1. 使用不同的 TLS 协议版本
    你可以尝试在 gradle.properties 文件中设置一个系统属性来允许 Gradle 使用其他版本的 TLS 协议。例如,将其设置为支持更旧的 TLS 协议版本:

systemProp.javax.net.ssl.protocols=TLSv1,TLSv1.1,TLSv1.2,TLSv1.3

  1. 更改 Gradle 仓库 URL 使用 HTTP
    因为部分仓库地址是使用 HTTPS 连接导致的兼容性问题,你可以暂时将仓库 URL 改为 HTTP。

在你的 build.gradle 文件中,更改所有依赖的仓库 URL 以使用 http 而不是 https。例如:

groovy 复制代码
repositories {
    maven {
        url "http://developer.huawei.com/repo/"
        allowInsecureProtocol = true
    }
}
相关推荐
2501_9159214321 小时前
从 HBuilder 到 App Store,uni-app 与 HBuilder 项目的 iOS 上架流程实战解析
android·ios·小程序·https·uni-app·iphone·webview
Yan-英杰1 天前
openEuler 数据库性能深度评测:PostgreSQL 全方位压测
网络·人工智能·网络协议·tcp/ip·http
bing.shao1 天前
Golang HTTP Restful 接口鉴权设计
http·golang·restful
游戏开发爱好者81 天前
以 uni-app 为核心的 iOS 上架流程实践, 从构建到最终提交的完整路径
android·ios·小程序·https·uni-app·iphone·webview
QING6181 天前
Kotlin Flow 去重 (distinctUntilChanged) 详解
kotlin·android studio·android jetpack
小曹要微笑1 天前
HTTP与WebSocket协议深度解析
websocket·网络协议·http·js
会头痛的可达鸭1 天前
HTTP 请求报文详解
网络·网络协议·http
HIT_Weston1 天前
54、【Ubuntu】【Gitlab】拉出内网 Web 服务:http.server 单/多线程分析(六)
网络协议·http·gitlab
游戏开发爱好者81 天前
构建可落地的 iOS 性能测试体系,从场景拆解到多工具协同的工程化实践
android·ios·小程序·https·uni-app·iphone·webview
基哥的奋斗历程1 天前
从零部署HTTPS网站完整指南-第一章
网络协议·http·https