Unable to find valid certification path to requested target

亲测有效,国内百度都是模棱两可的各种不成功,最终在谷歌搜索找到正解

原文 stackoverflow回答
https://stackoverflow.com/questions/42415666/errorcause-unable-to-find-valid-certification-path-to-requested-target

“Unable to find valid certification path to requested target”

If you are getting this message, you probably are behind a Proxy on your company, which probably is signing all request certificates with your company root CA certificate, this certificate is trusted only inside your company, so Android Studio cannot validate any certificate signed with your company certificate as valid, so, you need to tell Android Studio to trust your company certificate, you do that by adding your company certificate to Android Studio truststore.

(I’m doing this on macOS, but should be similar on Linux or Windows)

First, you need to save your company root CA certificate as a file: you can ask this certificate to your IT department, or download it yourself, here is how. Open your browser and open this url, for example, https://jcenter.bintray.com/ or https://search.maven.org/, click on the lock icon and then click on Show certificate

在这里插入图片描述
On the popup window, to save the root certificate as a file, make sure to select the top level of the certificates chain (the root cert) and drag the certificate image to a folder/directory on your disk drive. It should be saved as a file as, for example: my-root-ca-cert.cer, or my-root-ca-cert.pem

在这里插入图片描述
Second, let’s add this certificate to the accepted Server Certificates of Android Studio:

On Android Studio open Preferences -> Tools -> Server Certificates, on the box Accepted certificates click the plus icon (+), search the certificate you saved previously and click Apply and OK

在这里插入图片描述
Third, you need to add the certificate to the Android Studio JDK truststore (Gradle use this JDK to build the project, so it’s important):

In Android Studio open File -> Project Structure -> SDK Location -> JDK Location

在这里插入图片描述
Copy the path of JDK Location, and open the Terminal, and change your directory to that path, for example, execute:

cd /Applications/Android\ Studio.app/Contents/jre/jdk/Contents/Home/

(don’t forget to scape the whitespace, "\ ")

Now, to import the certificate to the truststore, execute:

./bin/keytool -importcert -file /path/to/your/certificate/my-root-ca-cert.cer -keystore ./jre/lib/security/cacerts -storepass changeit -noprompt

Finally, restart Android Studio, or better click File -> Invalidate Caches / Restart

Done, you should be able to build your project now.

  • 17
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这个错误通常是由于Android Studio无法找到有效的证书路径导致的。根据引用\[2\]的分析,这个问题可能是由于Android Studio默认只能以http://的形式进行网络访问,而当以https://的形式去拉取依赖包时会产生冲突,无法访问相应的网址,从而导致无效证书的错误。解决方法是将阿里云云仓镜像包的地址改为https://。\[2\] 另外,根据引用\[3\]的建议,还可以尝试以下两种方法解决这个问题: 1. 导入阿里云仓库的证书,并可以考虑将Google和JCenter的证书也加上。 2. 更换Android Studio编译使用的JAVA环境,不使用Android Studio自带的,而是使用电脑中其他的JDK。 综上所述,你可以尝试以上方法来解决"unable to find valid certification path to requested target"的问题。 #### 引用[.reference_title] - *1* *3* [【干货】解决AndroidStudio报错Cause: unable to find valid certification path to requested target](https://blog.csdn.net/qq_21154101/article/details/107886617)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [遇到Cause: unable to find valid certification path to requested target的另一种解决思路](https://blog.csdn.net/weixin_43622246/article/details/104905486)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值