【问题标题】:How to resolve repository certificate error in Gradle build如何解决 Gradle 构建中的存储库证书错误
【发布时间】:2017-11-16 07:28:26
【问题描述】:

我安装了最新版本的 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" }
}  

渐变脚本。但我仍然遇到同样的错误。如何修复此错误?

【问题讨论】:

  • 您有有效的互联网连接吗?在你的 android studio 首选项 -> Build, Execution -> Gradle 中,“离线工作”是否关闭?
  • 是的,Offline Work 已关闭...
  • 您在防火墙后面吗?你能在浏览器上下载这个文件https://dl.google.com/dl/android/maven2/com/android/support/appcompat-v7/26.1.0/appcompat-v7-26.1.0.pom吗?
  • 不,它会在浏览器中返回404 错误。
  • 我有这个错误。修理它?帮帮我

标签: java android maven


【解决方案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。将修改后的 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//

【讨论】:

  • 你给出了这么好的解释和正确的答案,很遗憾,它仍然没有被接受。谢谢
  • 这真是一个很好的解释。它对我有用。我刚刚在密钥库中导入了证书并且 tis 没有工作但是当我使用密钥库配置 gradle.proprties 时它开始工作。谢谢towa
  • 真的很有效,谢谢..
【解决方案2】:

在项目级别的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
}

然后,从应用级别 gradle 中删除 appcompat-v7:26.1.0 依赖项,然后下一步 转到 Android Studio 文件 > 项目结构 > 应用 > 依赖项 > 点击 + > 库依赖项 > 根据您的要求添加依赖项,然后确定。

您也可以尝试点击同步项目与 gradle 文件

更多内容请点击下方链接

https://developer.android.com/studio/build/gradle-plugin-3-0-0.html

已编辑

我认为您的问题有所不同,因此请使用以下链接,

"PKIX path building failed" and "unable to find valid certification path to requested target"

Resolving javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed Error?

https://github.com/appscode-ci/cibox/issues/16

https://www.mkyong.com/webservices/jax-ws/suncertpathbuilderexception-unable-to-find-valid-certification-path-to-requested-target/

【讨论】:

    【解决方案3】:

    您的 Java 不信任您用于下载库的链接。 在继续第 2 步之前,请先尝试第 1 步。

    1. 检查您的 Internet 是否位于任何防火墙之后,您的公司 Internet 可能会阻止您尝试访问的网站。将您的 PC 连接到移动互联网并尝试构建。

    2. 手动将证书添加到您的 jdk 证书存储区。

      • 例如访问网站https://example.com
      • 从浏览器下载证书。
      • 找到你的 jdk 安装目录。
      • 使用以下命令手动将证书添加到 cacerts,
      • sudo keytool -import -alias shibbolethnet -keystore
        /Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/jre/lib/security/cacerts -file <downloadedcert.cer>

    【讨论】:

      【解决方案4】:

      您可以尝试将 Gradle 包装器的路径更改为 Eclipse > Preferences > Gradle。选择本地安装目录而不是 Gradle Wrapper。

      【讨论】:

        【解决方案5】:

        我为plugins.gradle.org 安装了密钥并能够下载以下内容https://plugins.gradle.org/m2/org/springframework/boot/spring-boot-gradle-plugin/2.4.1/

        但是,无法下载https://plugins.gradle.org/m2/org/springframework/boot/spring-boot-gradle-plugin/2.4.1/spring-boot-gradle-plugin-2.4.1.module,我的浏览器可以下载。

        搞了一天搞清楚,url被重定向了,spring-boot-gradle-plugin-2.4.1.modulehttps://jcenter.bintray.com/org/springframework/boot/spring-boot-gradle-plugin/2.4.1/spring-boot-gradle-plugin-2.4.1.module

        在我的密钥库中添加了jcenter.bintray.com,它起作用了。扭曲的世界。

        【讨论】:

          【解决方案6】:

          尝试替换为

          repositories {
              maven { url 'http://repo1.maven.org/maven2' }
          }
          

          【讨论】:

          • 按照您的建议添加,仍然出现相同的错误。该错误与Trust Store 有关吗?
          • 切换回 http 而不是 https 在公司防火墙后面对我有用,尽管我认为这不是一个好的长期解决方案。
          猜你喜欢
          • 2016-11-02
          • 2022-11-28
          • 2020-01-09
          • 1970-01-01
          • 1970-01-01
          • 2019-10-07
          • 2016-10-21
          • 1970-01-01
          • 2012-10-02
          相关资源
          最近更新 更多