Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle sync failed: Cause: unable to find valid certification path to requested target on MacOS

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]
like image 490
Hrvoje Kobescak Avatar asked Mar 03 '21 09:03

Hrvoje Kobescak


2 Answers

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 ;)

like image 160
Aurélien Caraty Avatar answered Oct 18 '22 23:10

Aurélien Caraty


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

like image 6
Hrvoje Kobescak Avatar answered Oct 18 '22 23:10

Hrvoje Kobescak