最近在使用AR Foundation开发一些AR应用,在编译的时候,碰到一个问题。就是Gradle报错,定位了一下,查找到了解决方法。当前我使用的Unity 2019.3版本,所以在编译android版本的时候,需要注意。
报错信息如下:
[:arcore_client:] C:\Users\y00384577\.gradle\caches\transforms-2\files-2.1\b6f763c3be184b6b50c3a1bb135fb791\AndroidManifest.xml:30:9-54 Error:
Missing 'package' key attribute on element package at [:arcore_client:] AndroidManifest.xml:30:9-54
[:arcore_client:] C:\Users\y00384577\.gradle\caches\transforms-2\files-2.1\b6f763c3be184b6b50c3a1bb135fb791\AndroidManifest.xml Error:
Validation failed, exiting
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':launcher:processDebugManifest'.
> Manifest merger failed with multiple errors, see logs
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 2s
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
UnityEditor.EditorApplication:Internal_CallGlobalEventHandler()
CommandInvokationFailure: Gradle build failed.
D:\ProgramFile\java\jdk1.8.0_241\bin\java.exe -classpath "C:\Users\y00384577\.gradle\wrapper\dists\gradle-5.6.4-all\ankdp27end7byghfw1q2sw75f\gradle-5.6.4\lib\gradle-launcher-5.6.4.jar" org.gradle.launcher.GradleMain "-Dorg.gradle.jvmargs=-Xmx4096m" "assembleDebug"
stderr[
[:arcore_client:] C:\Users\y00384577\.gradle\caches\transforms-2\files-2.1\b6f763c3be184b6b50c3a1bb135fb791\AndroidManifest.xml:30:9-54 Error:
Missing 'package' key attribute on element package at [:arcore_client:] AndroidManifest.xml:30:9-54
[:arcore_client:] C:\Users\y00384577\.gradle\caches\transforms-2\files-2.1\b6f763c3be184b6b50c3a1bb135fb791\AndroidManifest.xml Error:
Validation failed, exiting
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':launcher:processDebugManifest'.
> Manifest merger failed with multiple errors, see logs
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 2s
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
]
stdout[
> Task :launcher:preBuild UP-TO-DATE
> Task :unityLibrary:preBuild UP-TO-DATE
> Task :unityLibrary:preDebugBuild UP-TO-DATE
> Task :launcher:prepareLintJar UP-TO-DATE
> Task :unityLibrary:checkDebugManifest UP-TO-DATE
> Task :unityLibrary:processDebugManifest
> Task :unityLibrary:compileDebugAidl NO-SOURCE
> Task :unityLibrary:packageDebugRenderscript NO-SOURCE
> Task :unityLibrary:compileDebugRenderscript NO-SOURCE
> Task :unityLibrary:generateDebugBuildConfig UP-TO-DATE
> Task :unityLibrary:generateDebugResValues UP-TO-DATE
> Task :unityLibrary:generateDebugResources UP-TO-DATE
> Task :unityLibrary:packageDebugResources UP-TO-DATE
> Task :unityLibrary:generateDebugRFile UP-TO-DATE
> Task :launcher:preDebugBuild
> Task :unityLibrary:prepareLintJar UP-TO-DATE
> Task :launcher:compileDebugAidl NO-SOURCE
> Task :unityLibrary:generateDebugSources UP-TO-DATE
> Task :launcher:compileDebugRenderscript NO-SOURCE
> Task :launcher:checkDebugManifest UP-TO-DATE
> Task :launcher:generateDebugBuildConfig UP-TO-DATE
> Task :launcher:generateDebugSources UP-TO-DATE
> Task :launcher:mainApkListPersistenceDebug UP-TO-DATE
> Task :launcher:generateDebugResValues UP-TO-DATE
> Task :launcher:generateDebugResources UP-TO-DATE
> Task :unityLibrary:javaPreCompileDebug UP-TO-DATE
> Task :unityLibrary:compileDebugJavaWithJavac UP-TO-DATE
> Task :unityLibrary:bundleLibCompileDebug UP-TO-DATE
> Task :unityLibrary:mergeDebugShaders UP-TO-DATE
> Task :unityLibrary:compileDebugShaders UP-TO-DATE
> Task :unityLibrary:generateDebugAssets UP-TO-DATE
> Task :unityLibrary:packageDebugAssets
> Task :unityLibrary:bundleLibRuntimeDebug UP-TO-DATE
> Task :unityLibrary:processDebugJavaRes NO-SOURCE
> Task :unityLibrary:bundleLibResDebug UP-TO-DATE
> Task :unityLibrary:mergeDebugJniLibFolders UP-TO-DATE
> Task :unityLibrary:transformNativeLibsWithMergeJniLibsForDebug UP-TO-DATE
> Task :unityLibrary:transformNativeLibsWithIntermediateJniLibsForDebug UP-TO-DATE
> Task :launcher:mergeDebugResources UP-TO-DATE
> Task :launcher:javaPreCompileDebug UP-TO-DATE
> Task :launcher:createDebugCompatibleScreenManifests UP-TO-DATE
> Task :launcher:processDebugManifest FAILED
See http://g.co/androidstudio/manifest-merger for more information about the manifest merger.
28 actionable tasks: 4 executed, 24 up-to-date
]
exit code: 1
UnityEditor.Android.Command.WaitForProgramToRun (UnityEditor.Utils.Program p, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <98f1d933052f4ea1953718dde49bfee4>:0)
UnityEditor.Android.Command.Run (System.Diagnostics.ProcessStartInfo psi, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <98f1d933052f4ea1953718dde49bfee4>:0)
UnityEditor.Android.Command.Run (System.String command, System.String args, System.String workingdir, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <98f1d933052f4ea1953718dde49bfee4>:0)
UnityEditor.Android.AndroidJavaTools.RunJava (System.String args, System.String workingdir, System.Action`1[T] progress, System.String error) (at <98f1d933052f4ea1953718dde49bfee4>:0)
UnityEditor.Android.GradleWrapper.Run (UnityEditor.Android.AndroidJavaTools javaTools, System.String workingdir, System.String task, System.Action`1[T] progress) (at <98f1d933052f4ea1953718dde49bfee4>:0)
Rethrow as GradleInvokationException: Gradle build failed
UnityEditor.Android.GradleWrapper.Run (UnityEditor.Android.AndroidJavaTools javaTools, System.String workingdir, System.String task, System.Action`1[T] progress) (at <98f1d933052f4ea1953718dde49bfee4>:0)
UnityEditor.Android.PostProcessor.Tasks.BuildGradleProject.Execute (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <98f1d933052f4ea1953718dde49bfee4>:0)
UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <98f1d933052f4ea1953718dde49bfee4>:0)
Rethrow as BuildFailedException: Exception of type 'UnityEditor.Build.BuildFailedException' was thrown.
UnityEditor.Android.PostProcessor.CancelPostProcess.AbortBuild (System.String title, System.String message, System.Exception ex) (at <98f1d933052f4ea1953718dde49bfee4>:0)
UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <98f1d933052f4ea1953718dde49bfee4>:0)
UnityEditor.Android.PostProcessAndroidPlayer.PostProcess (UnityEditor.BuildTarget target, System.String stagingAreaData, System.String stagingArea, System.String playerPackage, System.String installPath, System.String companyName, System.String productName, UnityEditor.BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry, UnityEditor.Build.Reporting.BuildReport report) (at <98f1d933052f4ea1953718dde49bfee4>:0)
UnityEditor.Android.AndroidBuildPostprocessor.PostProcess (UnityEditor.Modules.BuildPostProcessArgs args, UnityEditor.BuildProperties& outProperties) (at <98f1d933052f4ea1953718dde49bfee4>:0)
UnityEditor.PostprocessBuildPlayer.Postprocess (UnityEditor.BuildTargetGroup targetGroup, UnityEditor.BuildTarget target, System.String installPath, System.String companyName, System.String productName, System.Int32 width, System.Int32 height, UnityEditor.BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry, UnityEditor.Build.Reporting.BuildReport report) (at <51ff56607d9e437d85595c71a8c6fb65>:0)
UnityEditor.EditorApplication:Internal_CallGlobalEventHandler()
解决方法:
Unity 2020.1或更高版本
这些版本是使用Gradle 5.6.4或更高版本以及Gradle插件3.6.0或更高版本构建的。无需采取任何措施。
Unity 2019.3和2019.4
注意:以下定制仅在Unity 2019.3补丁7和更高版本上受支持。
1、转到Preferences > External Tools > Android > Gradle ,然后将自定义Gradle设置为Gradle 5.6.4或更高版本。请参阅Gradle构建工具以进行下载。、
2、转到Project Settings > Player > Android tab > Publishing Settings > Build ,然后选择两者:
- 自定义主Gradle模板
- 自定义启动器Gradle模板。
3、将以下更改应用于两个生成的文件:
Assets/Plugins/Android/mainTemplate.gradle
Assets/Plugins/Android/launcherTemplate.gradle
如果存在,请在文件顶部删除以下注释:
// GENERATED BY UNITY. REMOVE THIS COMMENT TO PREVENT OVERWRITING WHEN EXPORTING AGAIN
在文件顶部插入以下行:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
// Must be Android Gradle Plugin 3.6.0 or later. For a list of
// compatible Gradle versions refer to:
// https://developer.android.com/studio/releases/gradle-plugin
classpath 'com.android.tools.build:gradle:3.6.0'
}
}
allprojects {
repositories {
google()
jcenter()
flatDir {
dirs 'libs'
}
}
}
2019.1和2019.2
1、转到Preferences > External Tools > Android > Gradle Installed with Unity 。清除该选项,然后指定5.6.4或更高版本的自定义版本。请参阅Gradle构建工具以进行下载。
- 编辑生成的文件
Assets/Plugins/Android/mainTemplate.gradle
,然后根据您使用的Gradle版本将com.android.tools.build:gradle
依赖项设置为3.6.0或更高版本。
buildscript {
dependencies {
// Must be Android Gradle Plugin 3.6.0 or later. For a list of
// compatible Gradle versions refer to:
// https://developer.android.com/studio/releases/gradle-plugin
classpath 'com.android.tools.build:gradle:3.6.0'
}
}
Unity 2018.4
注意:以下定制仅在Unity 2018.4补丁24及更高版本上受支持。
1、转到 Build Settings > Android ,然后将Build System设置为Gradle以使用自定义的Gradle版本。
2、转到Preferences > External Tools > Android > Gradle Installed with Unity 。清除该选项,然后指定5.6.4或更高版本的自定义版本。请参阅Gradle构建工具以进行下载。
3、转到 Project Settings > Player > Android tab > Publishing Settings > Build, 选择 Custom Gradle Template.
4、编辑生成的文件Assets/Plugins/Android/mainTemplate.gradle
,然后根据您使用的Gradle版本将com.android.tools.build:gradle
依赖项设置为3.6.0或更高版本。
buildscript {
dependencies {
// Must be Android Gradle Plugin 3.6.0 or later. For a list of
// compatible Gradle versions refer to:
// https://developer.android.com/studio/releases/gradle-plugin
classpath 'com.android.tools.build:gradle:3.6.0'
}
}
按照这样配置就可以解决了,编译出错的问题。当然gradle默认的是使用google的maven地址,有时候下载编译的包会出错,可以更改自己的maven包。
buildscript {
repositories {
maven {
url "https://developer.huawei.com/repo/"
}
google()
jcenter()
}
dependencies {
// Must be Android Gradle Plugin 3.6.0 or later. For a list of
// compatible Gradle versions refer to:
// https://developer.android.com/studio/releases/gradle-plugin
classpath 'com.android.tools.build:gradle:3.6.0'
}
}
参考文献:
https://developers.google.com/ar/develop/unity/android-11-build#unity_20193_and_20194