Android 解決apk打包過程中出現的“Certificate for doesn't match any of the subject alternative names: [*.aktana.com, aktana.com]”的問題


 

有時候,apk打包過程中會出現“Certificate for <jcenter.bintray.com> doesn't match any of the subject alternative names: [*.aktana.com, aktana.com]”的錯誤。

 

這是因為本地計算機不能從jcenter.bintray.com上獲取編譯所需的某些jar包(被牆了)。

 

比如我的錯誤是:

Caused by: org.gradle.internal.resource.transport.http.HttpRequestException: Could not HEAD 'https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-stdlib/1.2.0/kotlin-stdlib-1.2.0.jar'.

獲取不到https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-stdlib/1.2.0/kotlin-stdlib-1.2.0.jar這個包。

 

fanqiang、修改host文件均不行。

 

 

有3種解決方式:

1、使用國內的Maven鏡像倉庫,需要修改build.gradle文件。此處我們使用阿里的鏡像倉庫。

原來的build.gradle文件:

 1 // Top-level build file where you can add configuration options common to all sub-projects/modules.
 2 
 3 buildscript {
 4     
 5     repositories {
 6         google()
 7         jcenter()
 8  mavenCentral() //修改此處,用maven{ url 'http://maven.aliyun.com/nexus/content/repositories/central/'}替換掉mavenCentral(),並放在jcenter()之前,保證被先訪問到  9     }
10     dependencies {
11         classpath 'com.android.tools.build:gradle:3.2.0'
12         
13 
14         // NOTE: Do not place your application dependencies here; they belong
15         // in the individual module build.gradle files
16     }
17 }
18 
19 allprojects {
20     repositories {
21         google()
22         jcenter()
23  mavenCentral() //此處也要修改 24     }
25 }
26 
27 task clean(type: Delete) {
28     delete rootProject.buildDir
29 }

 

修改過后的build.gradle文件:

 1 // Top-level build file where you can add configuration options common to all sub-projects/modules.
 2 
 3 buildscript {
 4     
 5     repositories {
 6         maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'} //必須放在jcenter()之前,否則無效  7         google()
 8         jcenter()
 9     }
10     dependencies {
11         classpath 'com.android.tools.build:gradle:3.2.0'
12         
13 
14         // NOTE: Do not place your application dependencies here; they belong
15         // in the individual module build.gradle files
16     }
17 }
18 
19 allprojects {
20     repositories {
21         maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'} 22         google()
23         jcenter()
24     }
25 }
26 
27 task clean(type: Delete) {
28     delete rootProject.buildDir
29 }

 

 重新編譯一遍,會自動下載缺少的jar包,成功。之后就可以順利打包apk了。

 

此種方式最簡單,也最有效,推薦。

 

 

 

 

 

2、手動修改jcenter()的訪問地址

 1 // Top-level build file where you can add configuration options common to all sub-projects/modules.
 2 
 3 buildscript {
 4     
 5     repositories {
 6         google()
 7         jcenter(){url 'http://maven.aliyun.com/nexus/content/groups/public/'} //此處使用的是阿里的鏡像倉庫  8        //注意:需要刪除maven()才有效
 9     }
10     dependencies {
11         classpath 'com.android.tools.build:gradle:3.2.0'
12         
13 
14         // NOTE: Do not place your application dependencies here; they belong
15         // in the individual module build.gradle files
16     }
17 }
18 
19 allprojects {
20     repositories {
21         google()
22        jcenter(){url 'http://maven.aliyun.com/nexus/content/groups/public/'} 23 
24     }
25 }
26 
27 task clean(type: Delete) {
28     delete rootProject.buildDir
29 }

 

已測,有效。

 

 

 

 

3、復制缺少的jar包的地址(報錯信息里有),比如我的是https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-stdlib/1.2.0/kotlin-stdlib-1.2.0.jar,使用迅雷下載,手動添加依賴。

很麻煩,十分容易出錯,及其不推薦。

 

不得不說迅雷還是很強,很多普通vpn搞不定的資源它還能下載。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM