Plain's Blog

休想打败我的生活🔥

Android Studio提示"Cause:unable to find valid certification path to requested target"的解决方法

Plain's Avatar 2020-01-10 安卓笔记

  1. 1. 1、报错说明
  2. 2. 2、解决方案
    1. 2.1. 到对应网站上获取其证书
    2. 2.2. 设置该证书

本文作者:feiyu

1、报错说明

如果为简略模式下看到的报错如下:

1
Cause: unable to find valid certification path to requested target

查看详细信息为:类似于下面

1
2
3
4
5
6
7
8
9
10
11
12
13
> Could not resolve all artifacts for configuration ':classpath'.
> Could not resolve com.android.tools.build:gradle:3.5.2.
Required by:
project :
> Could not resolve com.android.tools.build:gradle:3.5.2.
> Could not get resource 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.5.2/gradle-3.5.2.pom'.
> Could not GET 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.5.2/gradle-3.5.2.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.android.tools.build:gradle:3.5.2.
> Could not get resource 'https://jcenter.bintray.com/com/android/tools/build/gradle/3.5.2/gradle-3.5.2.pom'.
> Could not GET 'https://jcenter.bintray.com/com/android/tools/build/gradle/3.5.2/gradle-3.5.2.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 org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.50.

2、解决方案

上述问题直接原因为获取不到对应的资源,根本原因为证书无效(过期了?)

到对应网站上获取其证书

打开Chrome浏览器,输入

1
https://bintray.com/bintray/jcenter

点击最上方网址上的锁按钮(查看网站信息)

Kd230O

点击证书,然后查看其信息,如下所示:

8QmR1g

点击详细信息,然后点击复制到文件,如下所示:

bJyTye

点击下一步,继续生成证书:

Q3fOfp

选择Base64编码的格式,将证书导出到本地就可以了,例如qfh20200110jcenter.cer

设置该证书

Android StudioFile -> Settings -> Tools -> Server Certificates下,如下图所示:

kjjgiY

在可接收证书栏里,默认是空的(我的已经安装上了,所以不是空),点击加号,将刚才下载的证书安装提示安装上就可以了。

如果仍然存在问题的话,最上面的Accept non-trusted……选项也可以勾选上。

本文最后更新于 天前,文中所描述的信息可能已发生改变