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

Windows环境下React Native应用Gradle构建遭遇SSLHandshakeException

Windows下React Native Gradle构建SSLHandshakeException问题解决

问题场景

Windows环境中使用Gradle构建并安装React Native应用时,在依赖解析阶段抛出SSLHandshakeException错误,核心错误为PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target。

完整错误日志

What went wrong:
A problem occurred configuring root project 'app_name'.
> Could not determine the dependencies of task ':gradle-plugin:compileKotlin'.
   > javax.net.ssl.SSLHandshakeException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

BUILD FAILED in 12s
error Failed to install the app. Command failed with exit code 1: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081 FAILURE: Build failed with an exception.  
What went wrong: A problem occurred configuring root project 'app_name'. > Could not determine the dependencies of task ':gradle-plugin:compileKotlin'. > javax.net.ssl.
SSLHandshakeException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
Try: > Run with --stacktrace option to get the stack trace. > Run with --info or --debug option to get more log output. > Run with --scan to get full insights. > Get more
help at https://help.gradle.org. 

BUILD FAILED in 12s.

已尝试操作

  • 确认网络连接稳定
  • 执行带--info参数的构建以获取详细日志
  • 运行gradlew cleanBuildCache清理Gradle缓存,但问题仍未解决

解决方案

方法1:导入缺失的SSL证书到Java信任库

  1. 确定Gradle使用的JDK路径:在项目根目录执行gradlew -v,查看输出中"JVM:"行的路径(例如C:\Program Files\Java\jdk1.8.0_291)
  2. 导出目标仓库的SSL证书:打开浏览器访问Gradle依赖的仓库地址(如mavenCentral),点击地址栏锁图标,进入证书详情页,选择"复制到文件",保存为Base64编码的CER格式文件
  3. 导入证书到信任库:以管理员身份打开命令提示符,执行以下命令(替换路径为实际路径):
    keytool -import -alias mavenRepoCert -keystore "C:\Program Files\Java\jdk1.8.0_291\jre\lib\security\cacerts" -file "C:\downloads\maven_cert.cer"
    
    信任库默认密码为changeit,按提示输入密码并确认导入

方法2:配置Gradle跳过SSL验证(仅适用于测试环境)

  • 方式1:修改gradle.properties添加JVM参数
    在项目根目录的gradle.properties中加入以下配置:
org.gradle.jvmargs=-Djavax.net.ssl.trustStore="C:\Program Files\Java\jdk1.8.0_291\jre\lib\security\cacerts" -Djavax.net.ssl.trustStorePassword=changeit
  • 方式2:修改仓库配置使用HTTP或允许不安全协议
    在settings.gradle中修改仓库地址为HTTP,或添加allowInsecureProtocol true:
maven {
    url "http://repo1.maven.org/maven2/"
    // 或保留HTTPS并允许不安全协议
    // url "https://repo1.maven.org/maven2/"
    // allowInsecureProtocol true
}

方法3:检查并修正代理配置

若使用公司网络代理,确认Gradle代理配置正确:
在项目根目录的gradle.properties中添加代理信息(替换为实际代理地址):

systemProp.http.proxyHost=proxy.yourcompany.com
systemProp.http.proxyPort=8080
systemProp.https.proxyHost=proxy.yourcompany.com
systemProp.https.proxyPort=8080
systemProp.http.nonProxyHosts=localhost|127.0.0.1|*.yourcompany.com
systemProp.https.nonProxyHosts=localhost|127.0.0.1|*.yourcompany.com

若无需代理,可尝试关闭系统代理后重新执行构建


内容的提问来源于stack exchange,提问作者ayush ranjan

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.23 18:42:26