如何在Gradle构建中解决存储库证书错误
我安装了最新版的android studio。 我有已安装的jdk 8。 当我打开android studio时,我得到了以下错误。
Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve com.android.support:appcompat-v7:26.1.0. Could not resolve com.android.support:appcompat-v7:26.1.0. Required by: project :app > Could not resolve com.android.support:appcompat-v7:26.1.0. > Could not get resource 'https://dl.google.com/dl/android/maven2/com/android/support/appcompat-v7/26.1.0/appcompat-v7-26.1.0.pom'. > Could not GET 'https://dl.google.com/dl/android/maven2/com/android/support/appcompat-v7/26.1.0/appcompat-v7-26.1.0.pom'. > sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target > PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target > unable to find valid certification path to requested target
所以我删除了JDK 8并安装了JDK 9,添加了环境变量(在windows 10中)。 然后我重新启动了我的系统并启动了android studio,我仍然遇到了上述错误。 我甚至补充道
repositories { maven { url "https://maven.google.com" } }
gradle脚本。 但我仍然得到同样的错误。 我该如何解决这个错误?
以下步骤可能有助于:
1.将证书添加到密钥库 –
从Android Studio的cacerts将一些认证导入Android Studio JDK cacerts。
Android Studio的cacerts可能位于
{your-home-directory}/.AndroidStudio3.0/system/tasks/cacerts
我使用了以下import命令。
$ keytool -importkeystore -v -srckeystore {src cacerts} -destkeystore {dest cacerts}
2.将修改后的cacert路径添加到gradle.properties-
systemProp.javax.net.ssl.trustStore={your-android-studio-directory}\\jre\\jre\\lib\\security\\cacerts systemProp.javax.net.ssl.trustStorePassword=changeit
参考: https : //www.cresco.co.jp/blog/entry/2014/ /
根据下面的项目级别gradle进行修改
// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { google() jcenter() } dependencies { classpath 'com.android.tools.build:gradle:3.0.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { google() jcenter() } } task clean(type: Delete) { delete rootProject.buildDir }
然后,从app level gradle中删除appcompat-v7:26.1.0依赖关系然后转到Android Studio文件>项目结构> app>依赖关系>点击+>库依赖关系>根据您的要求添加依赖关系然后确定。
您也可以尝试使用gradle文件点击同步项目
欲了解更多信息,请访问以下链接
https://developer.android.com/studio/build/gradle-plugin-3-0-0.html
编辑
我认为您的问题有所不同所以请使用以下链接,
“PKIX路径构建失败”和“无法找到有效的证书路径到请求的目标”
解决javax.net.ssl.SSLHandshakeException:sun.security.validator.ValidatorException:PKIX路径构建失败错误?
尝试替换
repositories { maven { url 'http://repo1.maven.org/maven2' } }