Aandroid 解决apk打包过程中出现的“Certificate for doesn't match any of the subject alternative names: [*.aktana.com, aktana.com]”的问题

时间:2024-12-08 13:33:55

有时候,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这个包。

*、修改host文件均不行。

有3种解决方式:

1、使用国内的Maven镜像仓库,需要修改build.gradle文件。此处我们使用阿里的镜像仓库。

原来的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 'http://maven.aliyun.com/nexus/content/repositories/central/'}替换掉mavenCentral(),并放在jcenter()之前,保证被先访问到
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0' // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
} allprojects {
repositories {
google()
jcenter()
mavenCentral() //此处也要修改
}
} task clean(type: Delete) {
delete rootProject.buildDir
}

修改过后的build.gradle文件:

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

 buildscript {

     repositories {
maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'} //必须放在jcenter()之前,否则无效
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0' // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
} allprojects {
repositories {
maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'}
google()
jcenter()
}
} task clean(type: Delete) {
delete rootProject.buildDir
}

重新编译一遍,会自动下载缺少的jar包,成功。之后就可以顺利打包apk了。

此种方式最简单,也最有效,推荐。

2、手动修改jcenter()的访问地址

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

 buildscript {

     repositories {
google()
jcenter(){url 'http://maven.aliyun.com/nexus/content/groups/public/'} //此处使用的是阿里的镜像仓库
//注意:需要删除maven()才有效
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0' // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
} allprojects {
repositories {
google()
jcenter(){url 'http://maven.aliyun.com/nexus/content/groups/public/'}

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

已测,有效。

3、复制缺少的jar包的地址(报错信息里有),比如我的是https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-stdlib/1.2.0/kotlin-stdlib-1.2.0.jar,使用迅雷下载,手动添加依赖。

很麻烦,十分容易出错,及其不推荐。

不得不说迅雷还是很强,很多普通vpn搞不定的资源它还能下载。