preface

Today, I suddenly saw a private message on the CSDN App:

No mouble is easy to synchronize

Chicken boss, look at me in a minute

The price for that was a slap in the face and a car flip. Take note.

Car Go ~

The guy sent us an anomaly map, let’s take a look:

The brain thought along while, have not met this problem ah, say of what ghost certificate of thing. I switched from Windows to Mac OS, and Android Studio never saw that.

What do we do, boss chicken?

Ummm, go to the boss without thinking, easy to hate. Tap into Stack Overflow’s omnipotent Arsenal and find the following solution:

  • Resolving javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed Error?

Here is a special cut of the key solution, so that one day the magic can not open embarrassing, in fact, it is convenient for me, a lazy person, waka ~

Come on, let’s do it

Remote access to the young man’s computer, found that the connection to jCenter to download the relevant resource package is abnormal, so the operation is much easier ~

Download the certificate from jCenter’s official website

Click certificate to enter details:

Click “Copy to File…” Here, many of them are little point, and one key here only need main point, the export file format needs to be set as Base64 encoding, as shown in the figure below:

Step 2: Introduce two tools

Android Studio provides certificate management tools:

JDK certificate file:

Import the downloaded certificate into JDK Cacerts

Note here, Windows open CMD tool must be run as an administrator!! Note here, Windows open CMD tool must be run as an administrator!! Note here, Windows open CMD tool must be run as an administrator!!

Otherwise, cacerts will be prompted to deny access.

Type the following command line:

Keytool -import -alias [certificate alias] -keystore [JDK cacerts directory address] -file [download url]Copy the code

Key password: Changeit

The operation diagram is as follows:

“Do you trust this certificate? Enter y/ y.

Then clear the Android Studio cache and restart.

Set pieces

There are three steps to update the certificate safe point:

  • Keytool -list -keystore [JDK cacerts directory address]
  • Keytool -delete -alias [certificate alias] -keystore [JDK cacerts directory address]
  • Update certificate: keytool -import -alias [certificate alias] -keystore [JDK cacerts directory address] -file [download url]

Here are the details:

<! --> C:\Program Files\Android\Android Studio\jre\bin>keytool -list -keystore "C:\Program Files\Java\jdk1.8.0_91\jre\lib\security\cacerts" Enter keystore password: keystore type: JKS Keystore Provider: SUN Your keystore contains 102 entries... Certificate Fingerprint (SHA1): 74:20:7 4:41:7 2:9 C: DD: 92: EC: 79:31: D8:23:10:8 D: C2:81-92: E2: BB as, before 2020-2-17, trustedCertEntry, / / import certificate... <! Import certificate, --> C:\Program Files\Android\Android Studio\jre\bin>keytool -import -alias as -keystore "C:\Program Files\Java\jdk1.8.0_91\jre\lib\security\cacerts" -file C:\Users\86177\Downloads\as.cer Java.lang. Exception: Certificate not imported, alias <as> already exists <! --> C:\Program Files\Android\Android Studio\jre\bin>keytool -delete -alias as -keystore "C:\Program Files\Java\jdk1.8.0_91\jre\lib\security\cacerts" Enter key store password: <! --> C:\Program Files\Android\Android Studio\jre\bin>keytool -import -alias as -keystore "C:\Program Files\Java\jdk1.8.0_91\jre\lib\security\cacerts" -file C:\Users\86177\Downloads\as.cer Input keystore password: owner: CN=GeoTrust RSA CA 2018, OU=www.digicert.com, O=DigiCert Inc, C=US CN=GeoTrust RSA CA 2018, OU=www.digicert.com, O=DigiCert Inc, C=US The e6E is valid from Thu Sep 26 08:00:00 GMT+08:00 2019 to Tue Nov 09 20:00:00 GMT+08:00 2021Copy the code

The resources

  1. Resolving javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed Error?
  2. Java#PKIX path building failed