Android Studio - Unable to find valid certification path to requested target
Asked Answered
M

27

93

I'm getting this error

Gradle 'project_name' project refresh failed: Unable to find valid certification path to requested target

when I create a new project on Android Studio 0.8.14 Mac OSX

Build.gradle file seems to become empty

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.13.2'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    } }

allprojects {
    repositories {
        jcenter()
    } }

And I can't run the project, seems that I have to configure everything manually.

Here is the idea.log http://pastebin.com/kyhfrBp9

Milkmaid answered 2/11, 2014 at 7:44 Comment(4)
I would say that your build.gradle file is not so empty. This is the parent build.gradle and it doesn't define any common properties. Your module files (build.gradle) will have the individual entries for the compilation units in your project. Can you show me the contents of build.gradle (Module: ...)Alienor
when do you get this error ? Build ? Open a project ? . Is it stopping you from continuing ? Can you send that project fileAlienor
Hi I have fixed this issue make sure application level build gradle dependencies example classpath 'com.android.tools.build:gradle:2.3.3' should match with CordovaLib Dir build gradle dependencies classpath 'com.android.tools.build:gradle:2.3.3' Also, check if repositories { jcenter() } To repositories { maven { url "http://jcenter.bintray.com"} }Umpteen
Reboot one timeRato
D
101

It happened to me, and turned out it was because of Charles Proxy.

Charles Proxy is a HTTP debugging proxy server application

Solution (only if you have Charles Proxy installed):

  1. Shut down Charles Proxy;
  2. Restart Android Studio.
Displace answered 19/10, 2016 at 11:54 Comment(7)
Wow. Thanks. I would not have guessed.Whitewing
How do we shutdown CharlesProxy?Trochophore
@Trochophore it's a normal proxy application, just close it would be fine. If you don't know it, it's probably not the cause of your problem. Or you can check if you use any other proxy which might interfere your IDE's network activity.Displace
Would have been nice to read more about what Charles Proxy is, and what it does to cause trouble. Seems it prevents SSL communication somehow...Began
it is like the hundredth seventh time I fix some weird issue by closing Charles, thank youForebrain
Thank you for this. I thought I was going out of my mind, but it turns out I just forgot to quit Charles over the weekend.Stipel
Sometimes shutting it down does not help: go to Proxy > Stop SSL ProxyingDoall
P
75

"Unable to find valid certification path to requested target"

If you are getting this message, you probably are behind a Proxy on your company, which probably is signing all request certificates with your company root CA certificate, this certificate is trusted only inside your company, so Android Studio cannot validate any certificate signed with your company certificate as valid, so, you need to tell Android Studio to trust your company certificate, you do that by adding your company certificate to Android Studio truststore.

(I'm doing this on macOS, but should be similar on Linux or Windows)

  • First, you need to save your company root CA certificate as a file: you can ask this certificate to your IT department, or download it yourself, here is how. Open your browser and open this url, for example, https://jcenter.bintray.com/ or https://search.maven.org/, click on the lock icon and then click on Show certificate

enter image description here

On the popup window, to save the root certificate as a file, make sure to select the top level of the certificates chain (the root cert) and drag the certificate image to a folder/directory on your disk drive. It should be saved as a file as, for example: my-root-ca-cert.cer, or my-root-ca-cert.pem

enter image description here

  • Second, let's add this certificate to the accepted Server Certificates of Android Studio:

On Android Studio open Preferences -> Tools -> Server Certificates, on the box Accepted certificates click the plus icon (+), search the certificate you saved previously and click Apply and OK

enter image description here

  • Third, you need to add the certificate to the Android Studio JDK truststore (Gradle use this JDK to build the project, so it's important):

In Android Studio open File -> Project Structure -> SDK Location -> JDK Location

enter image description here

Copy the path of JDK Location, and open the Terminal, and change your directory to that path, for example, execute:

cd /Applications/Android\ Studio.app/Contents/jre/jdk/Contents/Home/

(don't forget to scape the whitespace, "\ ")

Now, to import the certificate to the truststore, execute:

./bin/keytool -importcert -file /path/to/your/certificate/my-root-ca-cert.cer -keystore ./jre/lib/security/cacerts -storepass changeit -noprompt
  • Finally, restart Android Studio, or better click File -> Invalidate Caches / Restart

Done, you should be able to build your project now.

Peso answered 25/11, 2020 at 1:11 Comment(10)
You saved my day !! I had only imported the certificate on my JDK HOME and not in Android Studio JREZirkle
Thank you. This is a really concise set of steps to add the certs. It really shouldn't be needed given that Android Studio has that nice tempting "Accept non-trusted certificates automatically" tickbox, but you still have to do these steps.Islaen
This should be an answer. Thanks Carlos!Zinnia
@Islaen Step 3 is necessary. Step 2 (or just checking the tick box you mentioned) is for Android Studio but not Gradle. Step 3 tackles the Gradle issue.Everard
Today, with Android Studio Artic Fox | 2020.3.1 Patch 2 freshly installed, the /jre folder not exists in my case ;) To import the certificate to the truststore : ./bin/keytool -importcert -file /path/to/your/certificate/my-root-ca-cert.cer -keystore lib/security/cacerts -storepass changeit -nopromptKlaraklarika
Thanks, I was having the same issue with the laptop with Zscaler installed. Your answers help to resolve the issue.Thirsty
This works with windows as well, just take care to download the top level of the certificates chain (the root cert). In chrome it can be opened via double clicking top one in Certification Path. Also the new path for cacerts is <Copied path of JDK Location>/lib/security/cacertsDex
The command to add certificate on Windows will look like keytool -importcert -alias my-root-ca-cert -file "<Path to saved top cert>\my-root-ca-cert.cer" -keystore "C:\Program Files\Android\Android Studio\jre\lib\security\cacerts" -storepass changeit -noprompt. Open the command prompt with administrator permissions.Dex
Note that restarting Android Studio or File -> Invalidate Caches / Restart is not enough. You have to resart your PC.Dex
Thank you very much! Worked well with Android studio bumblebee 2021.1.1 Patch 3 and Oracle JDK 11.Aubree
S
26

For me the issue was android studio was not able to establish connection with 'https://jcenter.bintray.com/'

Changing this to 'http' fixed the issue for me (Though this is not recommended).

In your build.gradle file, change

repositories {
   jcenter()
}

to

repositories {
   maven { url "http://jcenter.bintray.com"}
}
Spidery answered 9/12, 2016 at 9:7 Comment(4)
This fixed my issue. But now I am using something like artifactory to manage my reposIntricate
Please do not turn of SSL since this is a risk. Instead, import the missing certificate, see this comment below: https://mcmap.net/q/50016/-android-studio-unable-to-find-valid-certification-path-to-requested-targetBosomy
Was using gradle v2.2.2 and android Studio 3.5.3, the above solution didn't work for me.Cowbane
jcenter is no longer available over http. Only httpsInnate
O
21

If you are working in a restricted workplaces you probably will encounter this problem

A combination of a few things worked for me Basically change https to http

From https:

repositories {
   jcenter()
}

To :

repositories {
        maven { url "http://jcenter.bintray.com" }
   }

and in gradle-wrapper.properties ..

From :

    distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip

To :

   distributionUrl=http\://services.gradle.org/distributions/gradle-3.3-all.zip

And then

- (optional)  File -> Invalidate Caches / Restart`
- Give a clean build.

To verify : Check your Gradle console. It should start downloading libs from jcenter via HTTP.

Oscar answered 7/6, 2017 at 10:30 Comment(4)
its worked for me distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zipStepfather
Please do not turn of SSL/https, this is used for good reasons. Intall the SSL certificate as descibed in https://mcmap.net/q/50016/-android-studio-unable-to-find-valid-certification-path-to-requested-targetBegan
@Began I am not sure which certificate android studio is looking for. I have tried all the certificate in the link mentioned by you. Still facing the same issue. Can you point out a single certificate it is looking for ?Celanese
I have almost imported all the Digi cert certificates but no helpCelanese
T
21

Okay, Probably I am late but I have faced this issue after upgrading to 3.0.1 from 3.0. And this problem because I am working in restricted network.

The solution which worked for me is as follow:

Solution

Step 1: Get Certificate

jcenter() equals to https://bintray.com/bintray/jcenter

You need import jcenter's cerficate into your java keystore.

Visit jcenter using your browser and export the certificate as .cer file. (lock icon on the left of Firefox address bar, or Chrome developer tool secuity tab. Internet Explorer and Edge do not support saving of Website certificates, though.)

Step 2: Import Certificate In Android Studio, go to File -> Settings -> Tools -> Server Certificates.

Under Accept certificates click on + . Select the exported certificate.

Step 3: Refresh Keystore In Android Studio, go to File -> Invalidate Caches/Restart.... Select Invalidate and Restart from the message box that appears.

Tawanda answered 21/11, 2017 at 6:2 Comment(5)
how do i download the certificate ? i visited the bintray site and then ?Scallop
Visit jcenter using your browser and export the certificate as .cer file. (lock icon on the left of Firefox address bar, or Chrome developer tool secuity tab)Tawanda
no i could download it and add the .cer to the accepted certificates..but android studio is showing the same error.. !!Scallop
Ask your network guy to save your IP. To allow access to all jcenter\Google Repositort URL. Or download older version of Android studio like 3.0Tawanda
Didn't work :( I even checked 'Accept non-trusted certificates automatically'Lilah
B
17

I'm in an enterprise environment with a proxy/firewall/virus-scanner combination adding the company own SSL root certificate (self signed) to the trustpath of every SSL connection to investigate also into SSL connections. That was exactly the problem. If you are in the same situation this solution could help:

  1. Open https://jcenter.bintray.com in the browser (I prefer Firefox)
  2. Click on the padlock symbold to check the certificated trustpath. If the top/root certificate in the tree is a certficate signed by your company export it to your harddisk.
  3. To be safe export also every certificate in between
  4. Open the truststore of Android Studio in path JDKPATH/jre/lib/security/cacerts with the Keystore Explorer tool Keystore Exlorer with password "changeit"
  5. Import the exported certs into the trusstore starting with the root certificate of you company and go the step 6. In the most cases this will do the trick. If not, import the other certs as well step by step.
  6. Save the truststore
  7. Exit Android Studio with "File -> Invalidate Caches/Restart"
Barsac answered 30/5, 2018 at 11:46 Comment(5)
Followed the steps but still getting same error of SSL. Could not get resource :'dl.google.com/dl/android/maven2/com/android/tools/build/gradle/…'.Urbanist
If you are getting this error outside of Android Studio (e.g. with React Native CLI), then you need to forcibly restart the running Java process on the host machine (e.g. through Task Manager on Windows) to get certs to updateTowery
I'd also like to mention that in some cases Gradle/React Native/Android Studio may all use separate JDK/JRE keystores - you need to update the CA cert caches of all of them to get each to workTowery
First time it was not working for me.Was facing some exceptions when saving key store.**KSE Explorer** opened as Administrator ,and successfully able save to keystore and worked fine.Ulrica
JDKPATH in Step 4 would typically be $JAVA_HOME. But Android Studio uses embded JRE from "C:\Program Files\Android\Android Studio\jre" unless set otherwise. I got this fixed by changing "JDK Location" to value of $JAVA_HOME under File > Project Structure > SDK Location.Landscapist
M
14

Even though this question is very old, many must be facing the same issue, so I would like to state how I fixed this.

The problem is classpath 'com.android.tools.build:gradle:0.13.2' By above line in build.gradle you are asking it to find a particular version of gradle but this version is not there in your machine. The best it to change the above line to

classpath 'com.android.tools.build:gradle:+'
Monochord answered 31/8, 2016 at 16:5 Comment(1)
After looking through all the other answers this is the one that finally worked! Thank youSwellhead
I
14

jcenter() equals to https://bintray.com/bintray/jcenter

You need import jcenter's cerficate into your java keystore.

Steps:

  1. Visit jcenter using your browser and export the certificate as .crt file. (lock icon on the left of Firefox address bar, or Chrome developer tool secuity tab)
  2. Download this tool and run it.
  3. Select "Open an existing KeyStore" button to open JDKPATH/jre/lib/security/cacerts, the password is "changeit"
  4. Use the "Import Trusted Certificate" button to import the .crt file, then save and exist

If you are behind proxy, in gradle.properties, besides setting

systemProp.http.proxyHost and systemProp.http.proxyPort

also set

systemProp.https.proxyHost and systemProp.https.proxyPort

By now it should be fine.

Ilowell answered 24/5, 2017 at 1:6 Comment(4)
Along with the bintray cert, I also had to do this for the CA Certs internal to my company network.Corso
can you tell the process how you exported the bintray certificate ?Scallop
@SantanuSur: see below answer: https://mcmap.net/q/50016/-android-studio-unable-to-find-valid-certification-path-to-requested-targetAngelaangele
Thank you, this is the correct answer: update the keystore with the custom root cert to enable proper SSL transfer.Tempt
O
5

For me it was my internet, I was working on restricted network

Orton answered 3/3, 2017 at 18:38 Comment(3)
Did you find solution?Graft
@Ali. What If I cant switch to open. Did you got any solution..?Urbanist
This was my case. i switched to mobile networkTemplar
L
4

Seems like a bug to me. I've had the same problem and worked around it by manually starting gradlew.bat in my project directory.

Letta answered 3/11, 2014 at 15:13 Comment(0)
E
4

I had this problem today after upgrading to Android Studio 3.2 Beta 2. I had configured my JDK for OpenJDK 10.0.1, and it threw this error after upgrading. I set the JDK back to using the enbedded JDK, and the error went away.enter image description here

I have no idea why it worked fine before I upgraded to Beta 2, but all is good now. Honestly I guess there is no need for OpenJDK 10 for Android.

Eustacia answered 29/6, 2018 at 5:5 Comment(0)
D
3

Try to update your Android Studio, now is version 1.0.2

Duplicity answered 4/1, 2015 at 18:26 Comment(0)
N
3

I had this problem when makeing a new Android Wear OS project, and for me the problem solved just when I switched off my company's VPN for remote work and diconnected from the company network.

Noble answered 31/8, 2022 at 12:18 Comment(0)
E
1

Go to The Gradle Console in bottom right and open it.Here you will be seeing some https/https calls click on the links and open them in web browser then try clean build it worked for me.

I think It is happening because studio is not able to get the response from the hit.

Egwan answered 20/3, 2017 at 5:14 Comment(1)
Correct. My issue was that I was connected to a work place VPN and it was trying to build the project and to do that it was trying to automatically download the certificate but could not connect. Once I disconnected from VPN it worked without a problem.Raguelragweed
M
1

My company has us using FortiClient VPN, which caused this error to occur.

Try disconnecting from your VPN if applicable, and try again.

Mispleading answered 3/7, 2020 at 20:46 Comment(1)
The VPN is needed so this doesnt help muchFalcongentle
N
0

If you still have the problem, try deleting the directory named '.AndroidStudio1.2' under 'C:\Users\UserName\.AndroidStudio1.2'

Of course the name differs according to which version you have

That worked for me

Nonmoral answered 17/11, 2015 at 2:16 Comment(0)
N
0

Add latest gradle version properly in build.gradle file and latest distributionUrl in gradle-wrapper.properties file. [refer https://developer.android.com/studio/releases/gradle-plugin.html for the latest gradle version of android studio]

Make sure network connectivity is proper [ Network connection should not block upgrading gradle in android studio]. After gradle upgrade android studio will prompt alert to accept/decline certificate and we should accept the certificate.

Nellie answered 21/10, 2016 at 16:39 Comment(0)
Q
0

I got it because I'm behind a proxy. I had set the http but not the https proxy in gradle.properties. Https was needed in this case:

systemProp.http.proxyHost=<host>
systemProp.http.proxyPort=<port>
systemProp.https.proxyHost=<host>
systemProp.https.proxyPort=<port>

Also, take a look at the Android Studio logs for where the error could be.

Quadriceps answered 11/4, 2017 at 15:57 Comment(0)
U
0

It usually happen when your have included the dependency and it won't have repository reference like mavenCentral() or jcenter() etc to download it

What I usually do identify such dependency is set gradle to work offline, Android studio will automatically show a dependency which is not locally available, then look for the dependency details in their providers github page like from which repository to pick from and update your repositories and sink it. Hope it will work

Ucayali answered 24/7, 2017 at 14:27 Comment(0)
M
0

I faced similar error after upgrading to Android Studio 3.1.2 with gradle 4.4 & plugin 3.1.2, then tried almost all of the above solutions with generating the same error again & again.

Invalidate Caches / Restart finally have done me the favor: File>Invalidate Caches / Restart...>Invalidate and Restart

Machutte answered 14/5, 2018 at 6:34 Comment(0)
P
0

I had the same issue and it was caused because cyberoam was blocking my following URL

Caused by: org.gradle.api.resources.ResourceException: Unable to load Maven meta-data from https://maven.fabric.io/public/io/fabric/tools/gradle/maven-metadata.xml.

Plenum answered 5/7, 2018 at 9:25 Comment(0)
P
0

I changed(updated) my gradle version and it worked Form

classpath 'com.android.tools.build:gradle:3.1.4'

To

classpath 'com.android.tools.build:gradle:3.3.0'
Pecoraro answered 30/1, 2019 at 14:55 Comment(0)
A
0

Check proxy application like fiddler in your system, If its running close that application and restart your android studio

Albertype answered 3/12, 2020 at 5:19 Comment(0)
D
0

Since this is caused by a misconfiguration of the network you are operating on just setup your smartphone to share its internet connection using USB tethering and use it to download the missing packages.

Denizen answered 25/2, 2021 at 14:39 Comment(0)
H
0

If your IDE persistently gives proxy error or Unable to find valid certification path to requested target, this steps may be solve your problem,

If you have previously made manual Proxy settings, even though we have selected no proxy, you may still be able to see this section in gradle.properties.

So you may follow this steps: 1-) Open gradle.properties in your project and delete this items.

enter image description here

2-) Select No Proxy and Apply enter image description here

Try again.May be this solution help.

Harbot answered 15/12, 2023 at 6:23 Comment(0)
M
-1

Here is my solution for key phrases of the messages: “unable to find valid certification path” and “PKIX path building failed“.

These phrases are shown when a SSL certification file can not be found.

Open https://jcenter.bintray.com/ in your browse and export the certificate in cer format.

Put the certificate in Android Studio’s cert folder

{your-home-directory}/.AndroidStudio3.0/system/tasks/cacerts

Then all went well.

Mi answered 16/9, 2018 at 16:4 Comment(0)
L
-2

In my case below things identified

Causes - Take update from remote OR Checkout new branch

Resolution - The same issue has been resolved by disconnecting the VPN connection.

After Sync - Connect VPN again do your work as usual.

Lierne answered 19/8, 2022 at 13:18 Comment(2)
not working, vpn is required for internet access.Falcongentle
In my system, it's working with and without a VPN. VPN is needed for GIT operations only. I have also tried all the above solutions but have not resolved the problem. And then I tried disconnecting VPN and then resolved the problem.Lierne

© 2022 - 2024 — McMap. All rights reserved.