如何解决 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" }
}

分级脚本。但我仍然遇到同样的错误。我该如何解决这个错误?

原文由 Ajay Kulkarni 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 1.3k
1 个回答

以下步骤可能会有所帮助:

1.将证书添加到密钥库-

从 Android Studio 的 cacerts 导入一些认证到 Android Studio JDK cacerts。

Android Studio 的 cacerts 可能位于

{your-home-directory}/.AndroidStudio3.0/system/tasks/cacerts

我使用了以下导入命令。

 $ keytool -importkeystore -v -srckeystore {src cacerts} -destkeystore {dest cacerts}

2.在gradle.properties中添加修改cacert路径-

 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/ /

原文由 towa 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题