Java 如何解决 Gradle 构建中的存储库证书错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/47323909/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 02:35:40  来源:igfitidea点击:

How to resolve repository certificate error in Gradle build

javaandroidmaven

提问by Ajay Kulkarni

I installed latest version of android studio. I had jdk 8 which was already installed. When I opened android studio, I got below error.

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

So I removed JDK 8 and installed JDK 9, added environment variables (in windows 10). Then I restarted my system and started android studio, I still got above error. I even added

所以我删除了 JDK 8 并安装了 JDK 9,添加了环境变量(在 Windows 10 中)。然后我重新启动了我的系统并启动了 android studio,我仍然遇到上述错误。我什至补充说

repositories {
    maven { url "https://maven.google.com" }
}  

to gradle script. But I'm still getting same error. How do I fix this error?

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

回答by AndyJJ

try replace with

尝试替换为

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

回答by Dileep Patel

Modify in project level gradle according below

根据以下在项目级别的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
}

Then, remove appcompat-v7:26.1.0 dependency from app level gradle then next Go to Android Studio File > Project Structure > app >Dependencies > tap on + > Library Dependencies > add dependenceis as per your requirements then OK.

然后,从应用程序级别的 gradle 中删除 appcompat-v7:26.1.0 依赖项,然后转到 Android Studio File > Project Structure > app >Dependencies > 点击 + > Library Dependencies > 根据您的要求添加依赖项然后 OK。

Also you can try to tap on synchronize project with gradle file

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

synchronize with gradle file

与gradle文件同步

For more please go for below link

欲了解更多,请前往以下链接

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

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

Edited

已编辑

I think your problem is different so please go with below links,

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

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

“PKIX 路径构建失败”和“无法找到到请求目标的有效认证路径”

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

解决 javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed 错误?

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

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/

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

回答by towa

Below steps may help:

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

1. Add certificate to keystore-

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

Import some certifications into Android Studio JDK cacerts from Android Studio's cacerts.

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

Android Studio's cacerts may be located in

Android Studio 的 cacerts 可能位于

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

I used the following import command.

我使用了以下导入命令。

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

2. Add modified cacert path to gradle.properties-

2.将修改后的cacert路径添加到gradle.properties-

systemProp.javax.net.ssl.trustStore={your-android-studio-directory}\jre\jre\lib\security\cacerts
systemProp.javax.net.ssl.trustStorePassword=changeit

Ref : https://www.cresco.co.jp/blog/entry/2014//

参考:https: //www.cresco.co.jp/blog/entry/2014//

回答by Sucheth Shivakumar

Your Java is not trusting the link you are using to download library. Before proceeding on to step 2, Try step 1.

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

  1. Check if your internet is behind any firewall, Your company internet could be blocking the website you are trying to access. connect your PC to your mobile internet and trying building.

  2. Add certificate manually to your jdk cert strore.

    • Visit the website for example https://example.com
    • download the certificate from browser.
    • Find your jdk installation directory.
    • add cert manually to cacerts using below command,
    • sudo keytool -import -alias shibbolethnet -keystore
      /Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/jre/lib/security/cacerts -file <downloadedcert.cer>
  1. 检查您的互联网是否在任何防火墙之后,您公司的互联网可能会阻止您尝试访问的网站。将您的 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>

回答by Naveen

You can try changing the path for the Gradle wrapper going to Eclipse > Preferences > Gradle. Choose Local Installation directory instead of Gradle Wrapper.

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