解决AndroidStudio报错:unable to find valid certification path to requested target

本人在使用AndroidStudio过程中经常会遇到报错:unable to find valid certification path to requested target(找不到所请求目标的有效证书路径),后来就连新建hello world程序都会报错,在卸载重装降级都试过仍旧没有解决后去网上寻求解决方法。
在多次尝试之后总结出了以下几条解决方法

解决方法

方法一 从chrome浏览器获取证书

根据提示导入证书,去搜索了一下导入证书到AndroidStudio的步骤,首先找到错误的具体位置,往下找会找到一个或两个网址
在这里插入图片描述
将这段网址复制到chrome浏览器中,点击
在这里插入图片描述
选择证书
在这里插入图片描述
选择详细信息
在这里插入图片描述
点击复制到文件
在这里插入图片描述
选择保存位置后保存
之后做的就是将cer证书导入到cacerts证书库里
使用cmd进入dos命令行
在这里插入图片描述
在这里插入图片描述
默认密码是changeit,这里我先前已经添加过了
第一次添加会提示是否信任,这里选择 Y
添加信任后导入成功

这种方法较为简单,也有部分人能成功,但是没能解决我的问题

方法二 更换maven地址

更换maven地址
将原先的

google()
jcenter()

修改为

mavenCentral()
maven {
    url 'http://xxx' }

这里的地址为方法一中提到的错误位置的具体访问路径

仍然没有解决我的问题

方法三 手动新建并添加证书

第三种方法较为麻烦,本人也是在网上找了好久才找到,但是成功解决了我的AndroidStudio的问题

首先安装证书
1.新建一个java文件,然后将下面代码复制进去

/*
 * Copyright 2006 Sun Microsystems, Inc.  All Rights Reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 *   - Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *
 *   - Redistributions in binary form must reproduce the above copyright
 *     notice, this list of conditions and the following disclaimer in the
 *     documentation and/or other materials provided with the distribution.
 *
 *   - Neither the name of Sun Microsystems nor the names of its
 *     contributors may be used to endorse or promote products derived
 *     from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

import java.io.*;
import java.security.*;
import java.security.cert.*;
import javax.net.ssl.*;
public class InstallCert {
   

    public static void main(String[] args) throws Exception {
   
        String host = "10.0.31.32"; //输入服务端地址
        int port = 443; //输入服务端端口 一般默认443

        String p = "changeit"; //一般默认changeit
        char[] passphrase = p.toCharArray();

        File file = new File("jssecacerts");
        if (file.isFile() == false) {
   
            char SEP = File.separatorChar;
            File dir = new File(System.
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值