[android] Android Studio - Unable to find valid certification path to requested target

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

This question is related to android gradle android-studio certificate

The answer is


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.


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.


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.


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'

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.

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

Try to update your Android Studio, now is version 1.0.2


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


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.


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


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.


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


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.


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


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.


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"

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


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:+'

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


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.


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.


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

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


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.


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.


Examples related to android

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How to implement a simple scenario the OO way My eclipse won't open, i download the bundle pack it keeps saying error log getting " (1) no such column: _id10 " error java doesn't run if structure inside of onclick listener Cannot retrieve string(s) from preferences (settings) strange error in my Animation Drawable how to put image in a bundle and pass it to another activity FragmentActivity to Fragment A failure occurred while executing com.android.build.gradle.internal.tasks

Examples related to gradle

Gradle - Move a folder from ABC to XYZ A failure occurred while executing com.android.build.gradle.internal.tasks Gradle: Could not determine java version from '11.0.2' Android Gradle 5.0 Update:Cause: org.jetbrains.plugins.gradle.tooling.util Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0 Failed to resolve: com.android.support:appcompat-v7:28.0 Failed to resolve: com.google.firebase:firebase-core:16.0.1 com.google.android.gms:play-services-measurement-base is being requested by various other libraries java.lang.NoClassDefFoundError:failed resolution of :Lorg/apache/http/ProtocolVersion Error - Android resource linking failed (AAPT2 27.0.3 Daemon #0)

Examples related to android-studio

A failure occurred while executing com.android.build.gradle.internal.tasks "Failed to install the following Android SDK packages as some licences have not been accepted" error Android Gradle 5.0 Update:Cause: org.jetbrains.plugins.gradle.tooling.util This version of Android Studio cannot open this project, please retry with Android Studio 3.4 or newer WARNING: API 'variant.getJavaCompile()' is obsolete and has been replaced with 'variant.getJavaCompileProvider()' Flutter plugin not installed error;. When running flutter doctor ADB.exe is obsolete and has serious performance problems Android design support library for API 28 (P) not working Flutter command not found How to find the path of Flutter SDK

Examples related to certificate

Distribution certificate / private key not installed When you use 'badidea' or 'thisisunsafe' to bypass a Chrome certificate/HSTS error, does it only apply for the current site? Cannot install signed apk to device manually, got error "App not installed" Using client certificate in Curl command Convert .cer certificate to .jks SSL cert "err_cert_authority_invalid" on mobile chrome only Android Studio - Unable to find valid certification path to requested target SSL: error:0B080074:x509 certificate routines:X509_check_private_key:key values mismatch Verify a certificate chain using openssl verify Import Certificate to Trusted Root but not to Personal [Command Line]