Solve the Certificate error in Android Studio

Sana Ebadi
2 min readMar 18, 2021
Image from : https://www.raywenderlich.com/

In some companies, when installing JetBrains products, such as Android Studio, you will encounter a similar error that prevents your project from being built or synced:

“PKIX path building failed” and “unable to find valid certification path to requested target”

To solve this problem you have to go through a series of steps.

First find the keytool file. You can search for it, but you can usually find it in the following path:

C:\Program Files\Java\jdk1.8.0_65\bin

If you are using embedded JDK for Android Studio, just go to the Android Studio folder and find the keytool.

Note: If you have Linux or Mac, you must select the path with home or the path you specified for installation.

In the next step in the same path open cmd (for Linux or Mac terminal).

Go back to Android Studio and in the build window, look carefully at the errors in the window. The very first errors point to a series of links that Android Studio is unable to access.

For example, in my problem, it referred to this link, which was related to the gradel plugin

1.By opening this link in Browser:

  • firefox — click on HTTPS certificate chain (the lock icon right next to URL address). Click "more info" > "security" > "show certificate" > "details" > "export..". Pickup the name and choose file type example.cer
  • chrome — click on site icon left to address in address bar, select “Certificate” -> “Details” -> “Export” and save in format “Der-encoded binary, single certificate”.

2.Now you have file with keystore and you have to add it to your JVM. Determine location of cacerts files, eg. C:\Program Files (x86)\Java\jre1.6.0_22\lib\security\cacerts.

3.Next import the example.cer file into cacerts in command line (may need administrator command prompt):

You will be asked for password which default is changeit.

4.type another command :

5.type:

You must enter your company repository.for example: xx.nexus.xx:yyy

6.type:

7.and again trust it :

Restart your system once.

Then open your Android studio and start syncing the project.

DONE !

Thanks for reading! And if you enjoyed it, gimme a clap

Sana Ebadi |21:47 PM Thursday March 18, 2021

--

--