Aandroid 解决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这个包。
*、修改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搞不定的资源它还能下载。
上一篇: js根据json数组多个字段排序
下一篇: HTML页面导出PDF——高清版