(真正)解决Android Studio 4.0.1 Cause: unable to find valid certification path to requested target报错

使用Android Studio创建新的项目时,出现如下无效证书问题。

在这里插入图片描述

在网上看到各种各样的解决办法,但是都不奏效(如下载证书,然后添加进Android Studio中;更换国内镜像源等等)这些方法试过了都不是很奏效。

下面来说下我的看法:

首先,它报了证书无效这个错误,但其实和证书没有半毛钱的关系,因为根本或者不可能还会存在证书无效这个问题。其次,和自己所处的网络环境有很大关系,尽量别使用校园网,用手机开热点。因为校园网会对有些网站起到屏蔽作用。

解决办法:
步骤一:

在build.gradle文件中做如下的修改(切记不要有多余的操作,亲自尝试过会报证书失效错误),与下面代码保持一样即可。

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
    //将之前的全部注释掉,只添加下面两行;
        maven { url 'http://maven.aliyun.com/nexus/content/repositories/google' }
        maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter'}
    }
    dependencies {
        classpath "com.android.tools.build:gradle:4.0.1"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }

}
allprojects {
    repositories {
    //这个也是样操作
        maven { url 'http://maven.aliyun.com/nexus/content/repositories/google' }
        maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter'}
    }
}
步骤二

然后点击右上角的小象
在这里插入图片描述

步骤三

此时,不出意外的话还会出现Cause: unable to find valid certification path to requested target报错,不过不要慌。要接着做如下操作:点击File下的Invalidate Caches/Restart…,然后选择第一个重启Android Studio。
在这里插入图片描述
此时Android Studio 会重新下载相关包,此时应该就大功告成了。如果还出现Cause: unable to find valid certification path to requested target报错,那就 重复步骤三操作 ,很重要。重复几次后就会解决这个问题。

不得不说,Android Studio 自从更新之后,问题真的不少!!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值