使用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 自从更新之后,问题真的不少!!!