13

I have created a new project in android studio 3.0.1 setup the proxy settings of company and added the self sighned certificate unser server sertificates. When I try to build the following error is listed and the build fails.

Error:

Unable to resolve dependency for ':app@debug/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

Could somebody help me?

Zoe
  • 27,060
  • 21
  • 118
  • 148
ninjaxelite
  • 1,139
  • 2
  • 20
  • 43
  • Possible duplicate of [Could not resolve com.android.support:appcompat-v7:26.1.0.](https://stackoverflow.com/questions/47124746/could-not-resolve-com-android-supportappcompat-v726-1-0-configure-http-pro) – Roberto Martucci Dec 06 '17 at 15:56
  • 1
    This can not be cause I have set the gradle.properties for proxy. – ninjaxelite Dec 07 '17 at 08:07

6 Answers6

12

Solved this by adding the self signed certificate of my company to the cacerts file of Android Studio. The cacerts file is located here: C:\Program Files\Android\Android Studio\jre\jre\lib\security\cacerts

I have also added the proxy details for http/https to gradle.properties.

ninjaxelite
  • 1,139
  • 2
  • 20
  • 43
2

lets resolved this issue so go to the stack trace and see the first url of your stack trace where issue is pointed like in this post

https://dl.google.com/dl/android/maven2/com/android/support/appcompat-v7/26.1.0/appcompat-v7-26.1.0.pom

in your browser: but before that strip the last .pom or /filename.extension from your url.

  • in chrome - click on site of url icon left(lock icon in general) to address in address bar,

  • select "Certificate" -> "Certification Path"->select root node like "Corp-Prj-Root-CA"-> "View Certificate" -> "Details" -> "Copy to File..." and save in the format of "Der-encoded binary X.509(.CER)" single certificate file let name it rootCertFile.cer.

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

  • or check your android studio Java Path in Project settings

Next import the rootCertFile.cer file into cacerts

Solution1

using keytool in command line (you need to run as administrator command prompt):

keytool -import -alias example -keystore  "C:\Program Files (x86)\Java\jre1.6.0_22\lib\security\cacerts" -file rootCertFile.cer

You will be asked for password by default it is changeit

Solution2

you can use the keyExplorer software run as administrator and open the yourjavapath-> jre->lib->security-> cacerts file as per android studio path in it and

  • it will asked for password by default it is changeit enter then

  • click on the "Import Trusted certificate" icon or from Tools option and give the path of above saved certificate name rootCertFile.cer

  • then it will as for alias name give some unique name and press ok and

  • click on the save icon

  • also make sure about the proxy setting if any from company depend on certificate then that certificate also we need to add in same way

  • and we are done delete android studio caches directory and now try gradle sync in your project

Naval Kishor Jha
  • 894
  • 9
  • 13
1

Yeah, I have resolved the issue by changing the WiFi network connection. do any of the following step 1. connect to other or Mobile network(use hotspot) and reconnect to WiFi network 2. Reset your wifi network in laptop

Naresh Palle
  • 339
  • 3
  • 8
1

I fixed this issue by adding below script code in root build.gradle under buildscript tag

repositories {
        maven {
            url "https://jitpack.io"
        }
        maven {
            url "https://raw.github.com/Raizlabs/maven-releases/master/releases"
        }
        maven {
            url "http://oss.sonatype.org/content/repositories/snapshots"
            allowInsecureProtocol = true
        }
        maven {
            url "https://jcenter.bintray.com"
            allowInsecureProtocol = true
        }
        maven {
            url "https://plugins.gradle.org/m2/"
        }
        maven {
            url "https://maven.google.com"
        }
        google()
        jcenter()
    }

The key is to add

allowInsecureProtocol = true

AndroDev
  • 3,236
  • 8
  • 35
  • 49
0

lol, I have fixed this issue just by opening second link from error info https://dl.google.com/dl/android/maven2/com/android... in the Google Chrome. Then it has worked just like always ¯\ _ (ツ)_/¯

Vitalii Obideiko
  • 1,726
  • 1
  • 13
  • 16
0

Sometimes it helps to just upgrade to the latest gradle wrapper (gradle-wrapper.properties) and gradle plugin (main build.gradle -> buildscript -> dependencies -> com.android.tools.build:gradle). This is especially true if you're loading multiple projects and you've updated one of them. I did that and suddenly my "other" projects wouldn't sync/build. Updating them as well resolved that issue.

It bears noting that our company does have a very locked down network with tons of traffic sniffing and cert rewriting so that's likely the initial cause of the issue. Even with adding the self-signed certs into Android Studio's "approved" certificate list, I was still having issues until I did the above. Previously, I've even seen a difference between building in the terminal (./gradlew assembleDebug, which worked more often) and building in Android studio (which worked less often).