105

I got the following Error in android Studio 2.2.3 when I sync gradle.

Error:Cause: unable to find valid certification path to requested target

How can I fix this issue

I am Adding my Gradle file also

apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
    applicationId "com.sample.myapplication"
    minSdkVersion 16
    targetSdkVersion 22
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
} } dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'com.android.support:palette-v7:23.4.0'
testCompile 'junit:junit:4.12'
// FireBase
compile 'com.google.firebase:firebase-messaging:9.0.0'
}//Add this line
apply plugin: 'com.google.gms.google-services'

and the project Level Gradle File

buildscript {
repositories {
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:2.2.3'
    classpath 'com.google.gms:google-services:3.0.0'
}
}
allprojects {
repositories {
    mavenCentral()
    jcenter{ url "http://jcenter.bintray.com/" }
    maven { url "https://jitpack.io" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
12
  • 1
    I had this issue before, It go somehow solved by properly exiting the application, restarting pc, and then open app and rebuild graddle. Something to with local cache issue. app i mean android studio.
    – Smit
    Commented Feb 23, 2017 at 12:24
  • 1
    @Smit I tried that also but not fixed yet Commented Feb 24, 2017 at 4:43
  • Can you share you gradle code
    – Smit
    Commented Feb 24, 2017 at 5:19
  • @Smit aded the Gradle code in the question Commented Feb 24, 2017 at 6:10
  • Are you working in your house or in a company building?
    – Bisonfan95
    Commented Mar 4, 2017 at 17:43

26 Answers 26

109

This problem might be due to some restricted internet connections... If you are installing build tools on some restricted network, the required certificates might not install... So try changing the network connection.... Worked for me.....

6
  • 2
    Worked for me.... Earlier, I was working on my University network but I changed to my smartphone network, it worked for me. Commented Jun 12, 2018 at 17:23
  • 3
    Yep this did it for me too. I was on a corporate network and when I switched it worked.
    – Beezer
    Commented Jun 22, 2018 at 9:11
  • 3
    Had the same issue, turns out I had proxy turned on. Disabled it and it worked.
    – Ivan Leong
    Commented Feb 20, 2019 at 9:23
  • or disable a sort of web proxy and stackoverflow.com/a/62836938/4770877
    – yoAlex5
    Commented Jul 10, 2020 at 15:01
  • 1
    Restart Charles Proxy and disable proxying, ssl and recording
    – yoAlex5
    Commented Oct 7, 2020 at 14:59
73

I faced the same issue, but fixed it by adding

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

in the project Level Gradle File

buildscript {
repositories {
    jcenter()
    maven { url "http://jcenter.bintray.com"}
}
dependencies {
    classpath 'com.android.tools.build:gradle:2.2.3'
    classpath 'com.google.gms:google-services:3.0.0'
}
}
allprojects {
repositories {
    mavenCentral()
    jcenter{ url "http://jcenter.bintray.com/" }
    maven { url "https://jitpack.io" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
2
  • 1
    ok but why did this work? whats happening here thats causing this issue?
    – red888
    Commented Aug 4, 2020 at 21:04
  • Mine was an issue with McAffee. I had to disable it before gradle would sync properly.
    – James
    Commented Jan 25, 2022 at 7:41
46

"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.

6
  • Broken images didn't help any, but this answer DID fix my problem. I initially skipped the last step, which is what I truly needed.
    – IanCaz
    Commented Jan 18, 2021 at 19:43
  • 2
    in case you use jdk 11 this: ./jre/lib/security/cacerts should be: ./lib/security/cacerts Commented Apr 27, 2022 at 6:25
  • 1
    that last step really made myday. Thanks, buddy Commented Sep 20, 2022 at 19:27
  • 1
    Good explanation and even better solution that works even in 2023. Thanks a lot! FYI, if anybody's using Android Studio Preview versions like me, the path to keystore is then: lib/security/cacerts
    – Damercy
    Commented Jul 6, 2023 at 10:18
  • you can get your cacerts path in windows by using "%JAVA_HOME%\jre\lib\security\cacerts"
    – MrLittle
    Commented Mar 12 at 8:47
14

I have faced this problem with Maven build earlier. It was occurring because I was working in a restricted office network. You need to import required certificate in your keystore.

Follow Steps in the answer of below question "unable to find valid certification path to requested target", but browser says it's OK

(use double quotes for fienames/pathnames)

Note: I am not able to find now exact source from where I solved problem, if I get it, I will update it

3
13

Import your company certificate at Tools->Android->SDK Manager->Tools->Server Certificates

3
  • This is probably the correct answer, just make sure to restart IntelliJ after setting the cert.
    – dardo
    Commented May 9, 2018 at 16:32
  • 1
    I added certificate from bintray.com/bintray/jcenter. Restart studio and build was successful.
    – IfOnly
    Commented Apr 8, 2019 at 14:02
  • @IfOnly Can you link to where to get the cert for jcenter?
    – JPM
    Commented Aug 14, 2019 at 17:19
9

If you are running behind a corporate proxy with SSL interception, you will need to follow these steps to trust your proxy certificate for HTTPS:

  • In Android Studio, Open File -> Settings
    • In Tools -> Server Certificates
      • Tick ‘Accept non-trusted certificates automatically’
      • Also click the ‘+’ and manually add the corporate proxy root certificate.
    • In Appearance and Behaviour -> System Settings -> HTTP Proxy
      • Set your corporate proxy URL and port details
  • Download KeyStore Explorer: http://keystore-explorer.org/downloads.html
  • In KeyStore Explorer (run as admin), open the Android Studio JRE certificate store: C:\Program Files\Android\Android Studio\jre\jre\lib\security\cacerts
    • The password should be ‘changeit’
    • Import the corporate proxy root certificate, and save.
  • In Android Studio, select File -> Invalidate Cache and Restart
1
  • Thanks man, it solved my problem, this was exactly the problem I was experiencing, due to internal proxy restrictions.
    – rodolfocop
    Commented May 31, 2022 at 20:16
8

I just encountered the similar problem and found a series of steps did help me. Of course few of them is to Change the network to a stronger,better one.or if you have only one network then try Reconnecting to the network and then simply INVALIDATE/RESTART your android studio. If it still shows the error you need to add the "maven" in repositories and point it out to the link as shown below: maven { url "http://jcenter.bintray.com"}

Finally,Go to *File *Settings *Build,Execution and deployment *Gradle *Android Studio --------And check Enable maven repository option.

After that simply clean and rebuild your APP and you will be good to go.

1
  • 1
    The setting Android Studio > Enabled embeded marvin repository seems to finally make things work. Thanks.
    – Ben
    Commented Feb 23, 2019 at 11:20
7

If you re in your office ,use your smartphone network. I think It will work.

3
  • 1
    This saved my day. Commented Aug 19, 2019 at 6:51
  • 12
    This is NOT a solution
    – Phil
    Commented Oct 23, 2019 at 7:34
  • it worked for me ,cause my company network have more security
    – ozanurkan
    Commented Oct 23, 2019 at 8:11
4

I had the same problem. I fixed it by removing/commenting proxy settings in gradle.properties. Check your gradle.properties, if you have some like this

systemProp.https.proxyPort=8080
systemProp.http.proxyHost=192.168.1.1
systemProp.https.proxyHost=192.168.1.1
systemProp.http.proxyPort=8080

comment it with #. Which will look like this

#systemProp.https.proxyPort=8080
#systemProp.http.proxyHost=192.168.1.1
#systemProp.https.proxyHost=192.168.1.1
#systemProp.http.proxyPort=8080
3
  • 1
    Or just remove entirely. Commented Apr 3, 2019 at 20:47
  • @Zoe yes, we can but what if we need in the future? Better option is comment.
    – Vijay
    Commented Apr 18, 2019 at 18:44
  • 1
    This solved my problem - I mean removing the https proxy!
    – avijendr
    Commented Feb 1, 2021 at 21:46
3

I missed this problem after update studio and gradle ,in the log file tips me some maven store has certificate problem.

I tried restart statudio as somebody suggestion but dose work; and somebody said we should set the jre environment ,but I doesn't know how to set it on Mac . So I tried restart Mac. and start studio I found this tips.enter image description here

so the problem is floating on the surface: solution: first step: restart computer ,there are too many problem after android studio update . second step:use the old gradle tool OR download the *pom and jar ,put in correct folder.

2
  • I missed the same problem when my colleague update studio but I haven't update . Then I update studio ,but the problem occurs again . **I tried a lot of solution until this solved my problem. **. My computer is Mac.
    – kan137g
    Commented Apr 7, 2017 at 3:06
  • I missed the same problem again, all the solution description above doesn't work, then I closed Charles and restart studio , it's ok .
    – kan137g
    Commented Apr 18, 2017 at 7:15
3

Part of this answer by @Sadegh is what fixed it for me

Go to Gradle Scripts > gradle.properties

Enter these 6 lines in the gradle.properties file:

systemProp.http.proxyHost=fodev.org
systemProp.http.proxyPort=8118
systemProp.http.nonProxyHosts=*.jitpack.io, *.maven.org
systemProp.https.proxyHost=fodev.org
systemProp.https.proxyPort=8118
systemProp.https.nonProxyHosts=*.jitpack.io, *.maven.org

enter image description here

To dig deeper into the issue, I went inside Android Studio (not your mac), at the bottom I opened Terminal and entered: ./gradlew build --warning-mode all

The exact problem was:

PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

1
+50

You are using older version of libraries.

compile 'com.android.support:appcompat-v7:25.2.0'
compile 'com.android.support:design:25.2.0'
compile 'com.android.support:palette-v7:25.2.0'
compile 'com.google.firebase:firebase-messaging:10.2.0'
2
  • Update the gradle in the configuration and the error.
    – Sarvex
    Commented Mar 6, 2017 at 8:01
  • Error:Cause: unable to find valid certification path to requested target. This error I got when the gradle Sync Commented Mar 6, 2017 at 9:18
1

Like a noob!

I was getting a nightmare with this and forgot that i've recently installed a new AV (Kaspersky)

So another solution is: Disable your AV or add exclusions to your AV firewall or proxy

hope it helps to save some time.

1

For me this worked:

buildscript {
    repositories {
        maven { url "http://jcenter.bintray.com"}
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
    }
...
}

allprojects {
    repositories {
        mavenCentral()
        jcenter{ url "http://jcenter.bintray.com/" }
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
    }
}
1
  1. If you are using kotlin and its showing this error please update your kotlin gradle plugin in project level build.gradle.

  2. The certificate expired case : Go to certificates in settings and check if any certificate is expired if any, delete that certificate and clean and sync it will work.

  3. Dependencies- unable to find case : In this case delete that dependency and sync the project then add the dependency again with some another version(downgraded version) and sync the project it will work.

These three cases i faced and wasted so much time, hope this will help someone and save someones day.

Thankyou - happy coding**:-)**

1

Run bellow command in Android studio terminal after opening the same project. It worked for me.

On Windows:

gradlew cleanBuildCache

On Mac or Linux:

./gradlew cleanBuildCache
1
  • This worked for me. thank you so much! I first followed Minion point-2 and then your command.
    – Coder17
    Commented Dec 7, 2021 at 13:52
1

In my case, this error was caused by the Proxyman/Charles proxy tool. I fixed this by closing Proxyman, resetting the Android Studio cache and restarting the emulator. After that everything started working

1
  • 1
    Thank you. After I closed the charles and restarted the android studio the project started running Commented May 30 at 17:39
0

Just try to build the same project through command prompt and if the download dependencies happen successfully, go to settings in you IntelliJ and map the gradle to point gradle in your system and build should happen fine.

0

The error is is because of your network restriction that does not allow to sync the project from "http://jcenter.bintray.com", No need play with the IDE (Android Studio).

0

change dependencies from compile to Implementation in build.gradle file

0

Switching to the smartphone network & disabling the web security tool installed on my computer solved the problem.

1
  • This is a local solution, as there are people working in companies where they cannot disable security tool installed on their computer.
    – Olórin
    Commented Jan 21, 2020 at 15:42
0

This issue is related to network connectivity if not solved adding maven { url "http://jcenter.bintray.com"} at project level.

Just try to change your network and sync the gradle, should fix this issue for sure.

0

I got the same issue and I fixed it by changing my firewall setting or you can switch to another network

reasons behind it

when we are running our project run command its configure and check for exiting packages and make proceed to download the new or required package and the packages are stored on non-secure IP/hosting so your firewall will try to protect you and you will get these errors

0

Those who tried all the above answers and didn't help, or lazy to follow those steps, should try this quick-setting first.

  • Go to Android Studio -> Appearance & Behavior -> System Settings -> HTTP Proxy -> Select Auto-detect proxy settings

  • Go to Android Studio -> File -> Sync Project with Gradle File

enter image description here

-2

Most of the times when I face this issue. I remove replace https with http. It solves the issue.

3
  • 2
    Insecure connections aren't a good idea when you have options Commented Apr 2, 2019 at 6:03
  • I agree, But the firewall setting is taken care by the IT department, which I have no control on. What would u suggest as an alternative?
    – Irshad
    Commented Apr 2, 2019 at 6:11
  • 3
    Contacting the IT department and telling them to create/use a firewall that doesn't block basic dev tools Commented Apr 2, 2019 at 6:48
-2

Simple Invalidate/Restart fixed it for me. No other actions were taken

Not the answer you're looking for? Browse other questions tagged or ask your own question.