1

I am trying to build and apk in flutter so i run below command

flutter build apk --split-per-abi

After i run the command i get below error

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:131)
        at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:349)
        at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:292)
        at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:287)
        at java.base/sun.security.ssl.CertificateMessage$T12CertificateConsumer.checkServerCerts(CertificateMessage.java:654)
        at java.base/sun.security.ssl.CertificateMessage$T12CertificateConsumer.onCertificate(CertificateMessage.java:473)
        at java.base/sun.security.ssl.CertificateMessage$T12CertificateConsumer.consume(CertificateMessage.java:369)
        at java.base/sun.security.ssl.SSLHandshake.consume(SSLHandshake.java:392)
        at java.base/sun.security.ssl.HandshakeContext.dispatch(HandshakeContext.java:443)
        at java.base/sun.security.ssl.HandshakeContext.dispatch(HandshakeContext.java:421)
        at java.base/sun.security.ssl.TransportContext.dispatch(TransportContext.java:182)
        at java.base/sun.security.ssl.SSLTransport.decode(SSLTransport.java:172)
        at java.base/sun.security.ssl.SSLSocketImpl.decode(SSLSocketImpl.java:1426)
        at java.base/sun.security.ssl.SSLSocketImpl.readHandshakeRecord(SSLSocketImpl.java:1336)
        at java.base/sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:450)
        at java.base/sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:421)
        at java.base/sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:572)
        at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:197)
        at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1592)
        at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1520)
        at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:250)
        at org.gradle.wrapper.Download.downloadInternal(Download.java:58)
        at org.gradle.wrapper.Download.download(Download.java:44)
        at org.gradle.wrapper.Install$1.call(Install.java:61)
        at org.gradle.wrapper.Install$1.call(Install.java:48)
        at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:65)
        at org.gradle.wrapper.Install.createDist(Install.java:48)
        at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:128)
        at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)
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:439)
        at java.base/sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:306)
        at java.base/sun.security.validator.Validator.validate(Validator.java:264)
        at java.base/sun.security.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:313)
        at java.base/sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:222)
        at java.base/sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:129)
        at java.base/sun.security.ssl.CertificateMessage$T12CertificateConsumer.checkServerCerts(CertificateMessage.java:638)
        ... 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:434)

I have been able to use Maksym Anurin suggestion and i have built the app using below command


flutter build --verbose apk --split-per-abi

Below is the URL that is being tried to be accessed


[ +153 ms] Downloading https://services.gradle.org/distributions/gradle-7.4-all.zip

According to Shubhanshu Kashiva answer suggestions i should download the certificate from the target website and install certificate on my machine using keytool

The problem i am having is that the link does not have a certificate how can i go about that below is the screenshot from chrome

enter image description here

Emmanuel Njorodongo
  • 1,004
  • 17
  • 35
  • check this answer https://stackoverflow.com/a/9619478/12098728 – Shubhanshu Kashiva Jan 03 '23 at 03:50
  • @ShubhanshuKashiva where can i get the certificate from android studio – Emmanuel Njorodongo Jan 03 '23 at 09:58
  • try to run this command in terminal flutter doctor --android-licenses and check whether android licensing is there or not – Shubhanshu Kashiva Jan 03 '23 at 13:08
  • Try to build with more detailed log. Like: `flutter build --verbose apk --split-per-abi`. – Maksym Anurin Jan 05 '23 at 04:24
  • @MaksymAnurin This is what its saying before the error `[ +154 ms] Downloading https://services.gradle.org/distributions/gradle-7.4-all.zip` But when i paste the link in browser it just downloads the gradle without any problem – Emmanuel Njorodongo Jan 05 '23 at 13:15
  • So you have to add and trust CA Baltimore CyberTrust Root (that used in services.gradle.org). Basically this cert should be installed by OS updates... Do you update your OS? :) Anyway you free to install this CA yourself (details of this process out of scope the question) – Maksym Anurin Jan 05 '23 at 18:48
  • @MaksymAnurin yes i have updated my os to MacOs Ventura is there a way i can manually get the certificate and trust it myself – Emmanuel Njorodongo Jan 06 '23 at 13:12
  • Yes. CA cert https://cacerts.digicert.com/BaltimoreCyberTrustRoot.crt.pem. Videocast (for example) how to install https://www.youtube.com/watch?v=UMTDX79sz34 – Maksym Anurin Jan 06 '23 at 18:09

2 Answers2

0

Are you sure the SSL certificate is valid? The error is a javax.net.ssl.SSLHandshakeException which is caused by an inability to find a valid certification path to the requested target. This is likely due to an issue with the SSL certificate being used.

Usama Saleem
  • 103
  • 7
0

I suggest trying ./gradlew clean inside the android folder. If default certificates are messed up while downloading old gradle files and chached it in memory, this command will remove them.

Sometimes these kind of issues could be fixed by simple clean commands.

Aakash Kumar
  • 1,069
  • 7
  • 11