11

I have the following configuration:

  • MacOS 11.0.1 (MacOS firewall is off)
  • Android Studio 4.1.2
  • Android Gradle plugin version 4.1.1
  • Gradle version 6.5
  • Java jdk version 1.8.0_251

Gradle build started to report an error in all my projects, so I guess it's not related to a specific project config (build.gradle etc.).

The same projects are building and working normally on the same Android Studio, Gradle and JDK versions on Windows.

Steps I already tried but didn't help:

  • Rebuild project
  • Invalidate caches / restart
  • Reinstall Android Studio from scratch, followed instructions for complete uninstall (How to completely uninstall Android Studio on Mac?)
  • A clean install of freshly downloaded Android Studio from https://developer.android.com/studio
  • Make a clean install using JetBrains Toolbox
  • Manually add certificates (downloaded from browser) to both Android Studio (Preferences/Tools/Server certificates) and Java keystore
  • Install Android Studio 4.2 beta 5
  • Install a newer version of JDK (1.8.0_281)

Error details:
Gradle sync failed: Cause: unable to find valid certification path to requested target

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'name-of-the-project'.
> Could not resolve all artifacts for configuration ':classpath'.
   > Could not resolve com.android.tools.build:gradle:4.1.1.
     Required by:
         project :
      > Could not resolve com.android.tools.build:gradle:4.1.1.
         > Could not get resource 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/4.1.1/gradle-4.1.1.pom'.
            > Could not GET 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/4.1.1/gradle-4.1.1.pom'.
               > sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
   > Could not resolve com.google.gms:google-services:4.3.4.
     Required by:
         project :
      > Could not resolve com.google.gms:google-services:4.3.4.
         > Could not get resource 'https://dl.google.com/dl/android/maven2/com/google/gms/google-services/4.3.4/google-services-4.3.4.pom'.
            > Could not GET 'https://dl.google.com/dl/android/maven2/com/google/gms/google-services/4.3.4/google-services-4.3.4.pom'.
               > sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
   > Could not resolve com.google.firebase:firebase-crashlytics-gradle:2.4.1.
     Required by:
         project :
      > Could not resolve com.google.firebase:firebase-crashlytics-gradle:2.4.1.
         > Could not get resource 'https://dl.google.com/dl/android/maven2/com/google/firebase/firebase-crashlytics-gradle/2.4.1/firebase-crashlytics-gradle-2.4.1.pom'.
            > Could not GET 'https://dl.google.com/dl/android/maven2/com/google/firebase/firebase-crashlytics-gradle/2.4.1/firebase-crashlytics-gradle-2.4.1.pom'.
               > sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

It seems like it is a network problem, but I tried to use different connection solutions with different providers, with and without VPN.

All mentioned files are accessible and I can download them from terminal using wget

wget https://dl.google.com/dl/android/maven2/com/google/gms/google-services/4.3.4/google-services-4.3.4.pom
--2021-03-04 12:42:32--  https://dl.google.com/dl/android/maven2/com/google/gms/google-services/4.3.4/google-services-4.3.4.pom
Resolving dl.google.com (dl.google.com)... 216.58.214.206
Connecting to dl.google.com (dl.google.com)|216.58.214.206|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1576 (1,5K) [application/octet-stream]
Saving to: ‘google-services-4.3.4.pom.1’

google-services-4.3.4.pom.1                100%[=====================================================================================>]   1,54K  --.-KB/s    in 0s      

2021-03-04 12:42:32 (11,3 MB/s) - ‘google-services-4.3.4.pom.1’ saved [1576/1576]
Hrvoje Kobescak
  • 173
  • 1
  • 1
  • 8

4 Answers4

10

I've been stuck with the exact same bug for several days, and like you I tried pretty much everything.

Finally I noticed something in Android Studio. I went to the Http Proxy preference tab and I saw a message saying

You have JVM property "https.proxyHost" set to "localhost"....

I tried to override this value by putting the line :

systemProp.https.proxyHost=

In my project gradle.properties file and tadaaa ! It works, I don't really understand what happened though...

Hoping to be helpful ;)

6

After additional research... for some reason, MacOS network proxy settings were changed and that was the reason for the warning Android Studio made:

You have JVM property "https.proxyHost" set to "localhost"....

To fix this, go to

System Preferences / Network / Advanced (for network you are using) / Proxy

and unselect Web Proxy and Secure Web Proxy

Hrvoje Kobescak
  • 173
  • 1
  • 1
  • 8
1

There another possible reason for not getting a valid certificate path. The various plugins you use in your gradle build are not necessarily using the trust store that contains the certificates to validate the authenticity of the certificate in question. In my case, I could communicate with a given server using a browser with no certificate validating errors, but I couldn't do the same using the "maven-publish" plugin. Why, because they are using different trust stores for certificate validation. The "maven-publish" uses the trust store that java has been configured to use. The default location is in directory $JAVA_HOME/jre/lib/security. The browser is using your OS trust store. The java trust store can be changed using the system properties:

javax.net.ssl.trustStore,
javax.net.ssl.trustStorePassword
javax.net.ssl.trustStoreType

You can set them in the gradle.properties file using this format:

systemProp.javax.net.ssl.trustStore={path to your truststore}

You can also set them in you build.gradle.kts script using this format:

System.setProperty("javax.net.ssl.trustStorePassword", "{your truststore password")
Tom Rutchik
  • 1,183
  • 1
  • 12
  • 15
0

Originally answered here

In my case a proxy software installed on my mac was the culprit.

I faced this when I was trying build project on my Macbook. I tried so many solutions but none worked. Finally saw that the IT team had installed a proxy software and suspected that the proxy software could be blocking gradle to download the dependencies. I connected with IT Team and got the proxy uninstalled and then synced the project and it worked finally.

Ramakrishna Joshi
  • 1,442
  • 17
  • 22