unity2018.3.5版本及以上版本打包Android平台失败CommandInvokationFailure: Gradle build failed.

unity2018.3.5版本及以上版本打包Android平台失败CommandInvokationFailure: Gradle build failed.

问题描述:

unity2018.3.5版本打包Android平台出现报错CommandInvokationFailure: Gradle build failed.

在这里插入图片描述
Console控制台显示错误:
CommandInvokationFailure: Gradle build failed.
C:\Program Files\Unity\Editor\Data\PlaybackEngines\AndroidPlayer/Tools\OpenJDK\Windows\bin\java.exe -classpath “C:\Program Files\Unity\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\gradle\lib\gradle-launcher-4.6.jar” org.gradle.launcher.GradleMain “-Dorg.gradle.jvmargs=-Xmx4096m” “assembleRelease”

stderr[

FAILURE: Build failed with an exception.

  • What went wrong:
    A problem occurred configuring root project ‘gradleOut’.

Could not resolve all artifacts for configuration ‘:classpath’.
Could not resolve org.jetbrains.kotlin:kotlin-stdlib-jre8:1.2.0.
Required by:
project : > com.android.tools.build:gradle:3.2.0
project : > com.android.tools.build:gradle:3.2.0 > com.android.tools.build:builder:3.2.0
project : > com.android.tools.build:gradle:3.2.0 > com.android.tools.lint:lint-gradle-api:26.2.0
project : > com.android.tools.build:gradle:3.2.0 > com.android.tools.build:gradle-api:3.2.0
project : > com.android.tools.build:gradle:3.2.0 > androidx.databinding:databinding-compiler-common:3.2.0
project : > com.android.tools.build:gradle:3.2.0 > com.android.tools.build:builder:3.2.0 > com.android.tools:sdk-common:26.2.0
project : > com.android.tools.build:gradle:3.2.0 > com.android.tools.build:builder:3.2.0 > com.android.tools:common:26.2.0
project : > com.android.tools.build:gradle:3.2.0 > com.android.tools.build:builder:3.2.0 > com.android.tools.build:manifest-merger:26.2.0
project : > com.android.tools.build:gradle:3.2.0 > com.android.tools.build:builder:3.2.0 > com.android.tools:sdklib:26.2.0 > com.android.tools:repository:26.2.0
Could not resolve org.jetbrains.kotlin:kotlin-stdlib-jre8:1.2.0.
Could not get resource ‘https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-stdlib-jre8/1.2.0/kotlin-stdlib-jre8-1.2.0.pom’.
Could not GET ‘https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-stdlib-jre8/1.2.0/kotlin-stdlib-jre8-1.2.0.pom’.
sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
Could not resolve org.jetbrains.kotlin:kotlin-stdlib-jre8:1.2.0.
Could not get resource ‘https://dl.google.com/dl/android/maven2/org/jetbrains/kotlin/kotlin-stdlib-jre8/1.2.0/kotlin-stdlib-jre8-1.2.0.pom’.
Could not GET ‘https://dl.google.com/dl/android/maven2/org/jetbrains/kotlin/kotlin-stdlib-jre8/1.2.0/kotlin-stdlib-jre8-1.2.0.pom’.
sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
Could not resolve org.ow2.asm:asm:6.0.
Required by:
project : > com.android.tools.build:gradle:3.2.0
project : > com.android.tools.build:gradle:3.2.0 > com.android.tools.build:builder:3.2.0
project : > com.android.tools.build:gradle:3.2.0 > com.android.tools.build.jetifier:jetifier-processor:1.0.0-alpha10
Could not resolve org.ow2.asm:asm:6.0.
Could not get resource ‘https://jcenter.bintray.com/org/ow2/asm/asm/6.0/asm-6.0.pom’.
Could not HEAD ‘https://jcenter.bintray.com/org/ow2/asm/asm/6.0/asm-6.0.pom’.
sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
Could not resolve org.ow2.asm:asm:6.0.
Could not get resource ‘https://dl.google.com/dl/android/maven2/org/ow2/asm/asm/6.0/asm-6.0.pom’.
Could not HEAD ‘https://dl.google.com/dl/android/maven2/org/ow2/asm/asm/6.0/asm-6.0.pom’.
sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
Could not resolve org.ow2.asm:asm-analysis:6.0.
Required by:
project : > com.android.tools.build:gradle:3.2.0
Could not resolve org.ow2.asm:asm-analysis:6.0.
Could not get resource ‘https://jcenter.bintray.com/org/ow2/asm/asm-analysis/6.0/asm-analysis-6.0.pom’.
Could not HEAD ‘https://jcenter.bintray.com/org/ow2/asm/asm-analysis/6.0/asm-analysis-6.0.pom’.
sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
Could not resolve org.ow2.asm:asm-analysis:6.0.
Could not get resource ‘https://dl.google.com/dl/android/maven2/org/ow2/asm/asm-analysis/6.0/asm-analysis-6.0.pom’.
Could not HEAD ‘https://dl.google.com/dl/android/maven2/org/ow2/asm/asm-analysis/6.0/asm-analysis-6.0.pom’.
sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
Could not resolve org.ow2.asm:asm-commons:6.0.
Required by:
project : > com.android.tools.build:gradle:3.2.0
project : > com.android.tools.build:gradle:3.2.0 > com.android.tools.build:builder:3.2.0
project : > com.android.tools.build:gradle:3.2.0 > com.android.tools.build.jetifier:jetifier-processor:1.0.0-alpha10
Could not resolve org.ow2.asm:asm-commons:6.0.
Could not get resource ‘https://jcenter.bintray.com/org/ow2/asm/asm-commons/6.0/asm-commons-6.0.pom’.
Could not HEAD ‘https://jcenter.bintray.com/org/ow2/asm/asm-commons/6.0/asm-commons-6.0.pom’.
sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
Could not resolve org.ow2.asm:asm-commons:6.0.
Could not get resource ‘https://dl.google.com/dl/android/maven2/org/ow2/asm/asm-commons/6.0/asm-commons-6.0.pom’.
Could not HEAD ‘https://dl.google.com/dl/android/maven2/org/ow2/asm/asm-commons/6.0/asm-commons-6.0.pom’.
sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
Could not resolve org.ow2.asm:asm-util:6.0.
Required by:
project : > com.android.tools.build:gradle:3.2.0
project : > com.android.tools.build:gradle:3.2.0 > com.android.tools.build:builder:3.2.0
project : > com.android.tools.build:gradle:3.2.0 > com.android.tools.build.jetifier:jetifier-processor:1.0.0-alpha10
Could not resolve org.ow2.asm:asm-util:6.0.
Could not get resource ‘https://jcenter.bintray.com/org/ow2/asm/asm-util/6.0/asm-util-6.0.pom’.
Could not HEAD ‘https://jcenter.bintray.com/org/ow2/asm/asm-util/6.0/asm-util-6.0.pom’.
sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
Could not resolve org.ow2.asm:asm-util:6.0.
Could not get resource ‘https://dl.google.com/dl/android/maven2/org/ow2/asm/asm-util/6.0/asm-util-6.0.pom’.
Could not HEAD ‘https://dl.google.com/dl/android/maven2/org/ow2/asm/asm-util/6.0/asm-util-6.0.pom’.
sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
Could not resolve net.sf.jopt-simple:jopt-simple:4.9.
Required by:
project : > com.android.tools.build:gradle:3.2.0
project : > com.android.tools.build:gradle:3.2.0 > com.android.tools.build:builder:3.2.0
Could not resolve net.sf.jopt-simple:jopt-simple:4.9.
Could not get resource ‘https://jcenter.bintray.com/net/sf/jopt-simple/jopt-simple/4.9/jopt-simple-4.9.pom’.
Could not HEAD ‘https://jcenter.bintray.com/net/sf/jopt-simple/jopt-simple/4.9/jopt-simple-4.9.pom’.
sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
Could not resolve net.sf.jopt-simple:jopt-simple:4.9.
Could not get resource ‘https://dl.google.com/dl/android/maven2/net/sf/jopt-simple/jopt-simple/4.9/jopt-simple-4.9.pom’.
Could not HEAD ‘https://dl.google.com/dl/android/maven2/net/sf/jopt-simple/jopt-simple/4.9/jopt-simple-4.9.pom’.
sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
Could not resolve net.sf.proguard:proguard-gradle:6.0.3.
Required by:
project : > com.android.tools.build:gradle:3.2.0
Could not resolve net.sf.proguard:proguard-gradle:6.0.3.
Could not get resource ‘https://jcenter.bintray.com/net/sf/proguard/proguard-gradle/6.0.3/proguard-gradle-6.0.3.pom’.
Could not HEAD ‘https://jcenter.bintray.com/net/sf/proguard/proguard-gradle/6.0.3/proguard-gradle-6.0.3.pom’.
sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
Could not resolve net.sf.proguard:proguard-gradle:6.0.3.
Could not get resource ‘https://dl.google.com/dl/android/maven2/net/sf/proguard/proguard-gradle/6.0.3/proguard-gradle-6.0.3.pom’.
Could not HEAD ‘https://dl.google.com/dl/android/maven2/net/sf/proguard/proguard-gradle/6.0.3/proguard-gradle-6.0.3.pom’.
sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
Could not resolve com.squareup:javawriter:2.5.0.
Required by:
project : > com.android.tools.build:gradle:3.2.0 > com.android.tools.build:builder:3.2.0
Could not resolve com.squareup:javawriter:2.5.0.
Could not get resource ‘https://jcenter.bintray.com/com/squareup/javawriter/2.5.0/javawriter-2.5.0.pom’.
Could not HEAD ‘https://jcenter.bintray.com/com/squareup/javawriter/2.5.0/javawriter-2.5.0.pom’.
sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
Could not resolve com.squareup:javawriter:2.5.0.
Could not get resource ‘https://dl.google.com/dl/android/maven2/com/squareup/javawriter/2.5.0/javawriter-2.5.0.pom’.
Could not HEAD ‘https://dl.google.com/dl/android/maven2/com/squareup/javawriter/2.5.0/javawriter-2.5.0.pom’.
sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
Could not resolve org.bouncycastle:bcpkix-jdk15on:1.56.
Required by:
project : > com.android.tools.build:gradle:3.2.0 > com.android.tools.build:builder:3.2.0
project : > com.android.tools.build:gradle:3.2.0 > com.android.tools.build:builder:3.2.0 > com.android.tools:sdk-common:26.2.0
project : > com.android.tools.build:gradle:3.2.0 > com.android.tools.build:builder:3.2.0 > com.android.tools.build:apkzlib:3.2.0
Could not resolve org.bouncycastle:bcpkix-jdk15on:1.56.
Could not get resource ‘https://jcenter.bintray.com/org/bouncycastle/bcpkix-jdk15on/1.56/bcpkix-jdk15on-1.56.pom’.
Could not HEAD ‘https://jcenter.bintray.com/org/bouncycastle/bcpkix-jdk15on/1.56/bcpkix-jdk15on-1.56.pom’.
sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
Could not resolve org.bouncycastle:bcpkix-jdk15on:1.56.
Could not get resource ‘https://dl.google.com/dl/android/maven2/org/bouncycastle/bcpkix-jdk15on/1.56/bcpkix-jdk15on-1.56.pom’.
Could not HEAD ‘https://dl.google.com/dl/android/maven2/org/bouncycastle/bcpkix-jdk15on/1.56/bcpkix-jdk15on-1.56.pom’.
sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
Could not resolve org.bouncycastle:bcprov-jdk15on:1.56.
Required by:
project : > com.android.tools.build:gradle:3.2.0 > com.android.tools.build:builder:3.2.0
project : > com.android.tools.build:gradle:3.2.0 > com.android.tools.build:builder:3.2.0 > com.android.tools:sdk-common:26.2.0
project : > com.android.tools.build:gradle:3.2.0 > com.android.tools.build:builder:3.2.0 > com.android.tools.build:apkzlib:3.2.0
Could not resolve org.bouncycastle:bcprov-jdk15on:1.56.
Could not get resource ‘https://jcenter.bintray.com/org/bouncycastle/bcprov-jdk15on/1.56/bcprov-jdk15on-1.56.pom’.
Could not HEAD ‘https://jcenter.bintray.com/org/bouncycastle/bcprov-jdk15on/1.56/bcprov-jdk15on-1.56.pom’.
sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
Could not resolve org.ow2.asm:asm-tree:6.0.
Required by:
project : > com.android.tools.build:gradle:3.2.0 > com.android.tools.build:builder:3.2.0
Could not resolve org.ow2.asm:asm-tree:6.0.
Could not get resource ‘https://jcenter.bintray.com/org/ow2/asm/asm-tree/6.0/asm-tree-6.0.pom’.
Could not HEAD ‘https://jcenter.bintray.com/org/ow2/asm/asm-tree/6.0/asm-tree-6.0.pom’.
sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
Could not resolve it.unimi.dsi:fastutil:7.2.0.
Required by:
project : > com.android.tools.build:gradle:3.2.0 > com.android.tools.build:builder:3.2.0
Could not resolve it.unimi.dsi:fastutil:7.2.0.
Could not get resource ‘https://jcenter.bintray.com/it/unimi/dsi/fastutil/7.2.0/fastutil-7.2.0.pom’.
Could not HEAD ‘https://jcenter.bintray.com/it/unimi/dsi/fastutil/7.2.0/fastutil-7.2.0.pom’.
sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
Could not resolve org.codehaus.mojo:animal-sniffer-annotations:1.14.
Required by:
project : > com.android.tools.build:gradle:3.2.0 > com.android.tools.analytics-library:shared:26.2.0 > com.google.guava:guava:23.0
Could not resolve org.codehaus.mojo:animal-sniffer-annotations:1.14.
Could not get resource ‘https://jcenter.bintray.com/org/codehaus/mojo/animal-sniffer-annotations/1.14/animal-sniffer-annotations-1.14.pom’.
Could not HEAD ‘https://jcenter.bintray.com/org/codehaus/mojo/animal-sniffer-annotations/1.14/animal-sniffer-annotations-1.14.pom’.
sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
Could not resolve commons-logging:commons-logging:1.2.
Required by:
project : > com.android.tools.build:gradle:3.2.0 > com.android.tools.analytics-library:crash:26.2.0 > org.apache.httpcomponen

起初以为是SDK的原因,便更新了SDK,使用AndroidStudio下载高版本的SDK均没有解决问题,查找网上资料发现解决的方案大多为:
将Build System设置为Internal,虽然可以正常打包出APK,但是这样是治标不治本的。


原因分析:

在网上查找了一些资料,发现上面的解决方案涉及到签名证书,只是绕开了签名证书,所以这可能跟Android签名证书有关,最终找到了解决方案。


解决方案:

在PlayerSettings找到publishing Settings,勾选Create a new Keystore…,输入Keystore password和Confirm Keystore password,点击Browse Keystore保存签名证书到本地。在这里插入图片描述
然后就可以正常打包出来了。

这个错误通常是由于 Gradle 构建过程中出现了错误导致的。以下是一些可能的解决方法: 1. 清理 Gradle 缓存 在 Unity 中打开 Build Settings 窗口,点击 Player Settings 按钮,进入 Player Settings 界面。在 Android Settings 标签页中,找到 Other Settings 部分,将 "Custom Gradle Template" 选项取消勾选。然后在 Build Settings 窗口中选择 Android 平台,点击 "Export" 按钮,导出 Android 项目。然后在 Android Studio 中打开导出的项目,选择 "File" -> "Invalidate Caches / Restart...",清理 Gradle 缓存。然后重新构建 APK。 2. 升级 Gradle 版本Unity 中打开 Build Settings 窗口,选择 Android 平台,点击 "Player Settings" 按钮,进入 Player Settings 界面。在 Android Settings 标签页中,找到 "Publishing Settings" 部分,在 "Gradle Version" 中选择最新版本Gradle。然后重新构建 APK。 3. 检查依赖项 在 Unity 中打开 Build Settings 窗口,选择 Android 平台,点击 "Player Settings" 按钮,进入 Player Settings 界面。在 Android Settings 标签页中,找到 "Publishing Settings" 部分,检查 "Custom Gradle Template" 是否包含正确的依赖项。如果缺少某些依赖项,可以手动添加到 Gradle 文件中。然后重新构建 APK。 4. 检查 Android SDK 和 JDK 版本Unity 中打开 Build Settings 窗口,选择 Android 平台,点击 "Player Settings" 按钮,进入 Player Settings 界面。在 Android Settings 标签页中,找到 "Publishing Settings" 部分,检查 "Minimum API Level" 和 "Target API Level" 是否正确。然后检查是否安装了正确版本Android SDK 和 JDK。如果没有安装,可以手动下载并安装。然后重新构建 APK。 5. 检查 AndroidManifest.xml 文件 在 Android 项目中,检查 AndroidManifest.xml 文件是否包含正确的权限和组件声明。如果缺少某些声明,可以手动添加到 AndroidManifest.xml 文件中。然后重新构建 APK。 希望以上方法能够帮到您解决问题。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值