13

I installed latest version of android studio. I had jdk 8 which was already installed. When I opened android studio, I got below error.

Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve com.android.support:appcompat-v7:26.1.0.

Could not resolve com.android.support:appcompat-v7:26.1.0.
Required by:
    project :app
 > Could not resolve com.android.support:appcompat-v7:26.1.0.
    > Could not get resource 'https://dl.google.com/dl/android/maven2/com/android/support/appcompat-v7/26.1.0/appcompat-v7-26.1.0.pom'.
          > Could not GET 'https://dl.google.com/dl/android/maven2/com/android/support/appcompat-v7/26.1.0/appcompat-v7-26.1.0.pom'.
                   > sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
                               > PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
                                              > unable to find valid certification path to requested target  

So I removed JDK 8 and installed JDK 9, added environment variables (in windows 10). Then I restarted my system and started android studio, I still got above error. I even added

repositories {
    maven { url "https://maven.google.com" }
}  

to gradle script. But I'm still getting same error. How do I fix this error?

Rahul Sharma
  • 5,614
  • 10
  • 57
  • 91
Ajay Kulkarni
  • 2,900
  • 13
  • 48
  • 97

8 Answers8

21

Below steps may help:

1. Add certificate to keystore-

Import some certifications into Android Studio JDK cacerts from Android Studio’s cacerts.

Android Studio’s cacerts may be located in

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

I used the following import command.

$ keytool -importkeystore -v -srckeystore {src cacerts} -destkeystore {dest cacerts}

2. Add modified cacert path to gradle.properties-

systemProp.javax.net.ssl.trustStore={your-android-studio-directory}\\jre\\jre\\lib\\security\\cacerts
systemProp.javax.net.ssl.trustStorePassword=changeit

Ref : https://www.cresco.co.jp/blog/entry/2014//

towa
  • 211
  • 1
  • 4
0

Modify in project level gradle according below

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

buildscript {

repositories {
    google()
    jcenter()
}

dependencies {
    classpath 'com.android.tools.build:gradle:3.0.0'


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

allprojects {
     repositories {
      google()
      jcenter()
   }
 }

 task clean(type: Delete) {
  delete rootProject.buildDir
}

Then, remove appcompat-v7:26.1.0 dependency from app level gradle then next Go to Android Studio File > Project Structure > app >Dependencies > tap on + > Library Dependencies > add dependenceis as per your requirements then OK.

Also you can try to tap on synchronize project with gradle file

synchronize with gradle file

For more please go for below link

https://developer.android.com/studio/build/gradle-plugin-3-0-0.html

Edited

I think your problem is different so please go with below links,

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

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

https://github.com/appscode-ci/cibox/issues/16

https://www.mkyong.com/webservices/jax-ws/suncertpathbuilderexception-unable-to-find-valid-certification-path-to-requested-target/

Dileep Patel
  • 1,988
  • 2
  • 12
  • 26
0

Your Java is not trusting the link you are using to download library. Before proceeding on to step 2, Try step 1.

  1. Check if your internet is behind any firewall, Your company internet could be blocking the website you are trying to access. connect your PC to your mobile internet and trying building.

  2. Add certificate manually to your jdk cert strore.

    • Visit the website for example https://example.com
    • download the certificate from browser.
    • Find your jdk installation directory.
    • add cert manually to cacerts using below command,
    • sudo keytool -import -alias shibbolethnet -keystore
      /Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/jre/lib/security/cacerts -file <downloadedcert.cer>
0

You can try changing the path for the Gradle wrapper going to Eclipse > Preferences > Gradle. Choose Local Installation directory instead of Gradle Wrapper.

Naveen
  • 830
  • 9
  • 19
0

I installed key for plugins.gradle.org and was able to download the following, https://plugins.gradle.org/m2/org/springframework/boot/spring-boot-gradle-plugin/2.4.1/

However, failed to download https://plugins.gradle.org/m2/org/springframework/boot/spring-boot-gradle-plugin/2.4.1/spring-boot-gradle-plugin-2.4.1.module, which my browser is able to download.

Spent a day and figured out, the url is being redirected, spring-boot-gradle-plugin-2.4.1.modulehttps://jcenter.bintray.com/org/springframework/boot/spring-boot-gradle-plugin/2.4.1/spring-boot-gradle-plugin-2.4.1.module

Added jcenter.bintray.com to my keystore and it worked. Twisted world.

0

TL;DR

There are known JDK's with buggy HTTP client that fails during TLS v1.3 (enforced by many servers) with this misleading exception.

Update your JDK to newest possible version.

Long story

Version of JDK might be the cause. As the time progresses and the Internet evolves servers starting to narrow down the set of transport protocols. Some may only offer TLS v1.2 and TLS v1.3. HTTP Clients (including the one in Java) might be buggy.

My experience was that truststore and certificates were OK but as Java HTTP client from OpenJDK 11.0.0 (downloaded from official OpenJDK website) had a bug in TLS v1.3 it always ended up in exception PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target. Which is just exception thrown. Not the real problem.

Solution was to tak the freshest JDK from major version I had to use. It is fixed in 11.0.3 and by the time of writing 11.0.15 was available.

Číma
  • 11
  • 4
0

I was getting this error for a freshly cloned repo with a dependency was used successfully in another repo, so I knew it wasn't a key cert problem. Eventually I was able to resolve it by changing the gradle settings in intelliJ by going to Preferences ->Gradle -> Gradle JVM and setting it to the right JDK I wanted to use (I wanted java 1.8 but it was set to azul 15)

emily
  • 1
  • 1
-1

try replace with

repositories {
    maven { url 'http://repo1.maven.org/maven2' }
}
AndyJJ
  • 73
  • 1
  • 8
  • Added as you suggested, still getting same error. Is that error related to `Trust Store`? – Ajay Kulkarni Nov 16 '17 at 07:41
  • switching back to http instead of https worked for me behind a corporate firewall although I don't think it a good long term solution. – JesseBoyd Sep 24 '18 at 18:00