uni-app uniappX image组件在安卓5.1版本中 https图片不显示

uni-app uniappX image组件在安卓5.1版本中 https图片不显示

开发环境 版本号 项目创建方式
Mac Sequoia 15.3.2 HBuilderX
### bug描述:

uniapp-x  
安卓版本5.1

```html
<image class="image" src="https://xxx/a.jpg" mode="aspectFill" [@error](/user/error)="imageError"></image>

image组件调用 https图片 错误返回

[io.dcloud.uniapp.runtime.UniImageErrorEvent]  
{  
"detail":  
[io.dcloud.uniapp.runtime.UniImageErrorEventDetail]  
{  
"errMsg": "java.security.cert.CertPathValidatorException: Trust anchor for certification path not found."  
}  
}

操作步骤:

<image class="image" src="https://xxx/a.jpg" mode="aspectFill" [@error](/user/error)="imageError"></image>

预期结果:

预期可正常显示

实际结果:

图片不显示


更多关于uni-app uniappX image组件在安卓5.1版本中 https图片不显示的实战教程也可以访问 https://www.itying.com/category-93-b0.html

4 回复

麻烦提供一个可以复现问题的示例项目demo

更多关于uni-app uniappX image组件在安卓5.1版本中 https图片不显示的实战教程也可以访问 https://www.itying.com/category-93-b0.html


unix 直接在页面 <image class=“image” src=“https://xxx/a.jpg” mode=“aspectFill” @error=“imageError”></image> 安卓版本5.1里就看到问题了 http没问题 https就提示java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.

回复 艺宝皮皮: “https://xxx/a.jpg” 你给个你复现问题的地址吧 我这边测试都正常未复现问题

这是安卓5.1系统对TLS协议支持不足导致的HTTPS证书验证问题。以下是解决方案:

  1. 临时方案(不推荐): 在manifest.json中添加:
"app-plus": {
  "ssl": {
    "verify": false
  }
}

这会关闭证书验证,但存在安全风险。

  1. 推荐方案:
  • 升级服务器证书,确保支持TLS 1.2
  • 使用HTTP协议图片(非敏感图片)
  • 将图片转为base64内联
  • 使用本地图片资源
  1. 兼容方案:
<image v-if="isAndroid5" src="http://xxx/a.jpg" />
<image v-else src="https://xxx/a.jpg" />

在onLoad中判断系统版本:

const systemInfo = uni.getSystemInfoSync()
this.isAndroid5 = systemInfo.platform === 'android' && systemInfo.system.includes('5.1')
回到顶部