Ionic cordova run android not working/failing

hi, i’m trying to run my app to android phone, running through an emulator on localhost is not a problem.
However when i run the ionic cordova run android - i got an error as per below… appreciate the help as I been stuck for days… Is it because of the gradle problem?

Checking Java JDK and Android SDK versions
ANDROID_SDK_ROOT=C:\Users\me\AppData\Local\Android\Sdk (recommended setting)
ANDROID_HOME=C:\Users\me\AppData\Local\Android\Sdk (DEPRECATED)
Using Android SDK: C:\Users\me\AppData\Local\Android\Sdk
Subproject Path: CordovaLib
Subproject Path: app
Picked up _JAVA_OPTIONS: -Xmx1024M
Downloading https://services.gradle.org/distributions/gradle-6.5-all.zip
Exception in thread "main" javax.net.ssl.SSLException: java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty
        at sun.security.ssl.Alerts.getSSLException(Alerts.java:214)
        at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1958)
        at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1915)
        at sun.security.ssl.SSLSocketImpl.handleException(SSLSocketImpl.java:1898)
        at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1419)
        at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1396)
        at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:563)
        at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1512)
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1440)
        at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)
        at org.gradle.wrapper.Download.downloadInternal(Download.java:83)
        at org.gradle.wrapper.Download.download(Download.java:66)
        at org.gradle.wrapper.Install$1.call(Install.java:68)
        at org.gradle.wrapper.Install$1.call(Install.java:48)
        at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:69)
        at org.gradle.wrapper.Install.createDist(Install.java:48)
        at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:107)
        at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:63)
Caused by: java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty
        at sun.security.validator.PKIXValidator.<init>(PKIXValidator.java:90)
        at sun.security.validator.Validator.getInstance(Validator.java:179)
        at sun.security.ssl.X509TrustManagerImpl.getValidator(X509TrustManagerImpl.java:312)
        at sun.security.ssl.X509TrustManagerImpl.checkTrustedInit(X509TrustManagerImpl.java:171)
        at sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:184)
        at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:124)
        at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1508)
        at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:215)
        at sun.security.ssl.Handshaker.processLoop(Handshaker.java:1024)
        at sun.security.ssl.Handshaker.process_record(Handshaker.java:954)
        at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1065)
        at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1384)
        at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1412)
        ... 14 more
Caused by: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty
        at java.security.cert.PKIXParameters.setTrustAnchors(PKIXParameters.java:200)
        at java.security.cert.PKIXParameters.<init>(PKIXParameters.java:120)
        at java.security.cert.PKIXBuilderParameters.<init>(PKIXBuilderParameters.java:104)
        at sun.security.validator.PKIXValidator.<init>(PKIXValidator.java:88)
        ... 26 more
Command failed with exit code 1: C:\Users\me\Desktop\React\proj\platforms\android\gradlew cdvBuildDebug -b C:\Users\me\Desktop\React\proj\platforms\android\build.gradle
[ERROR] An error occurred while running subprocess cordova.

        cordova.cmd build android --device exited with exit code 1.

Ionic info:

Ionic:

   Ionic CLI                     : 6.16.3 (C:\Users\me\AppData\Roaming\npm\node_modules\@ionic\cli)
   Ionic Framework               : @ionic/angular 5.6.12
   @angular-devkit/build-angular : 12.1.4
   @angular-devkit/schematics    : 12.1.4
   @angular/cli                  : 12.1.4
   @ionic/angular-toolkit        : 4.0.0

Cordova:

   Cordova CLI       : 10.0.0
   Cordova Platforms : android 9.1.0
   Cordova Plugins   : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 4.2.1, (and 4 other plugins)

Utility:

   cordova-res : not installed globally
   native-run  : 1.4.0

System:

   Android SDK Tools : 26.1.1 (C:\Users\me\AppData\Local\Android\Sdk)
   NodeJS            : v14.17.3 (C:\Program Files\nodejs\node.exe)
   npm               : 6.14.13
   OS                : Windows 10

Gradle info:

C:\Users\me>gradle --version
Picked up _JAVA_OPTIONS: -Xmx1024M

------------------------------------------------------------
Gradle 6.5
------------------------------------------------------------

Build time:   2020-06-02 20:46:21 UTC
Revision:     a27f41e4ae5e8a41ab9b19f8dd6d86d7b384dad4

Kotlin:       1.3.72
Groovy:       2.5.11
Ant:          Apache Ant(TM) version 1.10.7 compiled on September 1 2019
JVM:          1.8.0_41 (Oracle Corporation 25.40-b25)
OS:           Windows 8.1 6.3 x86

This looks like a network environment problem to me. Is it feasible to try this from a totally different network? If not, can you ask whoever is in charge of administering the network that you are stuck on if they have any unusual proxy or firewall setups that could cause trouble resolving SSL certificates for services.gradle.org or its mirrors?

@rapropos I’ve check my network is perfectly fine. Also i change to other network too still issue persist. I turned off proxy though and firewall is on. Is it the gradle has a problem?

It seems to be that the “downloading gradle” process is having a problem, due to your Java environment not being happy with the SSL certificate chain of trust. Maybe try reinstalling JDK?

@rapropos i tried reinstall the java as you mention and it works by adding the environment variable accordingly thanks!!