java react-native run-android抛出无法找到证书

6vl6ewon  于 2023-02-14  发布在  Java
关注(0)|答案(1)|浏览(203)

bounty将于明天到期。回答此问题可获得+50的声望奖励。MrEngineer13希望吸引更多人关注此问题。

我在mac上工作,这是一个react原生项目,使用的是visual studio代码。只有当我从vs代码或终端中npx react-native run-android时,我才会收到此错误。我尝试访问gradle网站下载gradle。我尝试向我的项目添加调试密钥库。以下是完整的错误信息

  1. Exception in thread "main" javax.net.ssl.SSLHandshakeException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
  2. at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:130)
  3. at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:371)
  4. at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:314)
  5. at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:309)
  6. at java.base/sun.security.ssl.CertificateMessage$T13CertificateConsumer.checkServerCerts(CertificateMessage.java:1351)
  7. at java.base/sun.security.ssl.CertificateMessage$T13CertificateConsumer.onConsumeCertificate(CertificateMessage.java:1226)
  8. at java.base/sun.security.ssl.CertificateMessage$T13CertificateConsumer.consume(CertificateMessage.java:1169)
  9. at java.base/sun.security.ssl.SSLHandshake.consume(SSLHandshake.java:396)
  10. at java.base/sun.security.ssl.HandshakeContext.dispatch(HandshakeContext.java:480)
  11. at java.base/sun.security.ssl.HandshakeContext.dispatch(HandshakeContext.java:458)
  12. at java.base/sun.security.ssl.TransportContext.dispatch(TransportContext.java:201)
  13. at java.base/sun.security.ssl.SSLTransport.decode(SSLTransport.java:172)
  14. at java.base/sun.security.ssl.SSLSocketImpl.decode(SSLSocketImpl.java:1510)
  15. at java.base/sun.security.ssl.SSLSocketImpl.readHandshakeRecord(SSLSocketImpl.java:1425)
  16. at java.base/sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:455)
  17. at java.base/sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:426)
  18. at java.base/sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:578)
  19. at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:187)
  20. at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1661)
  21. at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1585)
  22. at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:224)
  23. at org.gradle.wrapper.Download.downloadInternal(Download.java:100)
  24. at org.gradle.wrapper.Download.download(Download.java:80)
  25. at org.gradle.wrapper.Install$1.call(Install.java:82)
  26. at org.gradle.wrapper.Install$1.call(Install.java:62)
  27. at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:69)
  28. at org.gradle.wrapper.Install.createDist(Install.java:62)
  29. at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:107)
  30. at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:63)

Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target at java.base/sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:388) at java.base/sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:271) at java.base/sun.security.validator.Validator.validate(Validator.java:256) at java.base/sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:231) at java.base/sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:132) at java.base/sun.security.ssl.CertificateMessage$T13CertificateConsumer.checkServerCerts(CertificateMessage.java:1335) ... 24 more Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target at java.base/sun.security.provider.certpath.SunCertPathBuilder.build(SunCertPathBuilder.java:141) at java.base/sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:126) at java.base/java.security.cert.CertPathBuilder.build(CertPathBuilder.java:297) at java.base/sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:383) ... 29 more ​ error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup . Error: Command failed: ./gradlew app:installQadebug -PreactNativeDevServerPort=8081 Exception in thread "main" javax.net.ssl.SSLHandshakeException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:130) at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:371) at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:314) at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:309) at java.base/sun.security.ssl.CertificateMessage$T13CertificateConsumer.checkServerCerts(CertificateMessage.java:1351) at java.base/sun.security.ssl.CertificateMessage$T13CertificateConsumer.onConsumeCertificate(CertificateMessage.java:1226) at java.base/sun.security.ssl.CertificateMessage$T13CertificateConsumer.consume(CertificateMessage.java:1169) at java.base/sun.security.ssl.SSLHandshake.consume(SSLHandshake.java:396) at java.base/sun.security.ssl.HandshakeContext.dispatch(HandshakeContext.java:480) at java.base/sun.security.ssl.HandshakeContext.dispatch(HandshakeContext.java:458) at java.base/sun.security.ssl.TransportContext.dispatch(TransportContext.java:201) at java.base/sun.security.ssl.SSLTransport.decode(SSLTransport.java:172) at java.base/sun.security.ssl.SSLSocketImpl.decode(SSLSocketImpl.java:1510) at java.base/sun.security.ssl.SSLSocketImpl.readHandshakeRecord(SSLSocketImpl.java:1425) at java.base/sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:455) at java.base/sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:426) at java.base/sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:578) at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:187) at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1661) at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1585) at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:224) at org.gradle.wrapper.Download.downloadInternal(Download.java:100) at org.gradle.wrapper.Download.download(Download.java:80) at org.gradle.wrapper.Install$1.call(Install.java:82) at org.gradle.wrapper.Install$1.call(Install.java:62) at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:69) at org.gradle.wrapper.Install.createDist(Install.java:62) at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:107) at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:63) Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target at java.base/sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:388) at java.base/sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:271) at java.base/sun.security.validator.Validator.validate(Validator.java:256) at java.base/sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:231) at java.base/sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:132) at java.base/sun.security.ssl.CertificateMessage$T13CertificateConsumer.checkServerCerts(CertificateMessage.java:1335) ... 24 more Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target at java.base/sun.security.provider.certpath.SunCertPathBuilder.build(SunCertPathBuilder.java:141) at java.base/sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:126) at java.base/java.security.cert.CertPathBuilder.build(CertPathBuilder.java:297) at java.base/sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:383) ... 29 more ​ at makeError (/Users/JWimer/StudioProjects/cw-mobile-react-native-git/node_modules/@react-native-community/cli-platform-android/node_modules/execa/index.js:174:9) at /Users/JWimer/StudioProjects/cw-mobile-react-native-git/node_modules/@react-native-community/cli-platform-android/node_modules/execa/index.js:278:16 at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async runOnAllDevices (/Users/JWimer/StudioProjects/cw-mobile-react-native-git/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js:109:5) at async Command.handleAction (/Users/JWimer/StudioProjects/cw-mobile-react-native-git/node_modules/@react-native-community/cli/build/index.js:142:9)

s2j5cfk0

s2j5cfk01#

当您尝试在Android模拟器或设备上运行React Native应用,并且构建过程因找不到安装应用所需的签名证书而失败时,通常会出现此错误消息。
以下是您可以尝试解决此问题的几个步骤:
生成新的签名证书:如果没有签名证书,可以使用JavaSDK附带的keytool实用程序生成一个。
您可以使用以下命令生成新证书:

  1. keytool -genkeypair -v -keystore my-release-key.keystore -alias my-key-alias -keyalg RSA -keysize 2048 -validity 10000

指定签名证书的路径:在React Native项目中,您需要在android/app/build. gradle文件中指定签名证书的路径。您可以将以下代码添加到该文件以指定路径:

  1. android {
  2. ...
  3. signingConfigs {
  4. release {
  5. storeFile file("my-release-key.keystore")
  6. storePassword "storePassword"
  7. keyAlias "my-key-alias"
  8. keyPassword "keyPassword"
  9. }
  10. }
  11. buildTypes {
  12. release {
  13. ...
  14. signingConfig signingConfigs.release
  15. }
  16. }
  17. }

运行应用程序:指定签名证书的路径后,你应该能够运行该应用而不会遇到错误消息。你可以使用以下命令运行该应用:

  1. react-native run-android
展开查看全部

相关问题