HttpRequestException: Could not GET XXX,unable to find valid certification path to requested target

軟件版本

Android Studio 3.6.3

 

java version "1.8.0_171"
Java(TM) SE Runtime Environment (build 1.8.0_171-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.171-b11, mixed mode)

 

Gradle 5.6.3

 

 

異常信息

org.gradle.internal.resource.transport.http.HttpRequestException: Could not GET XXX

javax.net.ssl.SSLHandshakeException: 
sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

 

解決

在使用搜索引擎查看此異常解決方法時,嘗試了多種方法,最後還是解決了,記錄一下。

 

 

location build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    
    repositories {
//        google()
//        jcenter()

        mavenCentral()
        maven { url 'https://maven.google.com' }
        maven { url 'https://jcenter.bintray.com'}
        maven {
            url 'https://maven.aliyun.com/nexus/content/groups/public/'
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.6.3'
        

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
//        google()
//        jcenter()

        mavenCentral()
        maven { url 'https://maven.google.com' }
        maven { url 'https://jcenter.bintray.com'}
        maven {
            url 'https://maven.aliyun.com/nexus/content/groups/public/'
        }
        
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

 

app build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    buildToolsVersion "29.0.3"

    defaultConfig {
        applicationId "com.xiangqian.location"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

 

Project Structure

 

HTTP Proxy

mirrors.neusoft.edu.cn

可以使用代理和不使用代理進行嘗試。

 

Android SDK

 

 

使用portecle工具添加證書

1、portecle下載地址:http://sourceforge.net/projects/portecle/files/latest/download

2、解壓portecle-1.11.zip

3、在解壓後的文件夾中,可看到有一個portecle.jar,使用命令行運行此jar即可,$ java -jar portecle.jar

4、獲取證書文件並保存到本地。注意,根據報錯信息,我只需要獲取https://dl.google.com、https://jcenter.bintray.com、https://maven.aliyun.com、https://maven.google.com

PEM Encoding

將證書文件保存到本地。

 

5、將證書文件添加到 jdk1.8.0_66\jre\lib\security\cacerts中

密碼默認是:changeit

 

 

添加證書

 

添加證書後記得點擊“保存”

 

 

 

清除緩存並重新啓動Android Studio

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章