Unity打包报错A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFa
Posted 鱼蛋-Felix
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Unity打包报错A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFa相关的知识,希望对你有一定的参考价值。
最近预见一个奇葩事,明明前几天的版本打包安卓正常的,也正常打包出apk了,然后改了点东西突然就不行了,通过版本控制svn还原到之前能正常打包的版本,也报一样的错误,真是活见鬼了。
报错信息如下:
* What went wrong:
Execution failed for task ':launcher:packageRelease'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
> value (4304957338) > 0x00000000ffffffffL
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':launcher:packageRelease'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
> value (4304957338) > 0x00000000ffffffffL
* 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 5m 31s
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
]
stdout[
Starting a Gradle Daemon, 1 incompatible and 2 stopped Daemons could not be reused, use --status for details
> Configure project :launcher
WARNING: The option 'android.enableR8' is deprecated and should not be used anymore.
It will be removed in a future version of the Android Gradle plugin, and will no longer allow you to disable R8.
> Task :launcher:preBuild UP-TO-DATE
> Task :unityLibrary:preBuild UP-TO-DATE
> Task :unityLibrary:unity-android-resources:preBuild UP-TO-DATE
> Task :launcher:preReleaseBuild UP-TO-DATE
> Task :unityLibrary:unity-android-resources:preReleaseBuild UP-TO-DATE
> Task :unityLibrary:preReleaseBuild UP-TO-DATE
> Task :unityLibrary:unity-android-resources:compileReleaseAidl NO-SOURCE
> Task :unityLibrary:packageReleaseRenderscript NO-SOURCE
> Task :unityLibrary:unity-android-resources:packageReleaseRenderscript NO-SOURCE
> Task :unityLibrary:unity-android-resources:compileReleaseRenderscript NO-SOURCE
> Task :launcher:generateReleaseBuildConfig
> Task :unityLibrary:unity-android-resources:generateReleaseResValues
> Task :unityLibrary:generateReleaseBuildConfig
> Task :unityLibrary:unity-android-resources:generateReleaseResources
> Task :unityLibrary:compileReleaseAidl NO-SOURCE
> Task :launcher:compileReleaseRenderscript NO-SOURCE
> Task :unityLibrary:compileReleaseRenderscript NO-SOURCE
> Task :unityLibrary:generateReleaseResValues
> Task :unityLibrary:generateReleaseResources
> Task :launcher:mainApkListPersistenceRelease
> Task :launcher:compileReleaseAidl NO-SOURCE
> Task :launcher:generateReleaseResValues
> Task :launcher:generateReleaseResources
> Task :launcher:createReleaseCompatibleScreenManifests
> Task :launcher:extractDeepLinksRelease
> Task :launcher:prepareLintJar
> Task :launcher:checkReleaseDuplicateClasses
> Task :unityLibrary:unity-android-resources:packageReleaseResources
> Task :unityLibrary:packageReleaseResources
> Task :unityLibrary:extractDeepLinksRelease
> Task :unityLibrary:unity-android-resources:generateReleaseBuildConfig
> Task :unityLibrary:unity-android-resources:extractDeepLinksRelease
> Task :unityLibrary:unity-android-resources:parseReleaseLocalResources
> Task :unityLibrary:mergeReleaseShaders
> Task :unityLibrary:compileReleaseShaders
> Task :unityLibrary:generateReleaseAssets
> Task :unityLibrary:unity-android-resources:mergeReleaseShaders
> Task :unityLibrary:unity-android-resources:compileReleaseShaders
> Task :unityLibrary:unity-android-resources:generateReleaseAssets
> Task :unityLibrary:unity-android-resources:packageReleaseAssets
> Task :unityLibrary:unity-android-resources:processReleaseJavaRes NO-SOURCE
> Task :launcher:mergeReleaseShaders
> Task :launcher:compileReleaseShaders
> Task :launcher:generateReleaseAssets
> Task :launcher:processReleaseJavaRes NO-SOURCE
> Task :unityLibrary:unity-android-resources:processReleaseManifest
> Task :launcher:mergeReleaseJniLibFolders
> Task :launcher:validateSigningRelease
> Task :unityLibrary:unity-android-resources:mergeReleaseJniLibFolders
> Task :unityLibrary:unity-android-resources:prepareLintJarForPublish
> Task :unityLibrary:unity-android-resources:bundleLibResRelease
> Task :unityLibrary:unity-android-resources:javaPreCompileRelease
> Task :unityLibrary:unity-android-resources:generateReleaseRFile
> Task :unityLibrary:unity-android-resources:compileReleaseJavaWithJavac
> Task :unityLibrary:unity-android-resources:mergeReleaseNativeLibs
> Task :unityLibrary:unity-android-resources:stripReleaseDebugSymbols
> Task :unityLibrary:unity-android-resources:copyReleaseJniLibsProjectOnly
> Task :unityLibrary:unity-android-resources:bundleLibRuntimeRelease
> Task :unityLibrary:unity-android-resources:bundleLibCompileRelease
> Task :launcher:mergeReleaseResources
> Task :launcher:desugarReleaseFileDependencies
> Task :unityLibrary:unity-android-resources:compileReleaseLibraryResources
> Task :launcher:mergeExtDexRelease
> Task :unityLibrary:parseReleaseLocalResources
> Task :unityLibrary:processReleaseManifest
> Task :unityLibrary:compileReleaseLibraryResources
> Task :unityLibrary:prepareLintJarForPublish
> Task :unityLibrary:packageReleaseAssets
> Task :unityLibrary:processReleaseJavaRes NO-SOURCE
> Task :unityLibrary:mergeReleaseJniLibFolders
> Task :unityLibrary:javaPreCompileRelease
> Task :unityLibrary:bundleLibResRelease
> Task :unityLibrary:generateReleaseRFile
> Task :unityLibrary:compileReleaseJavaWithJavac
> Task :unityLibrary:bundleLibRuntimeRelease
> Task :unityLibrary:bundleLibCompileRelease
> Task :unityLibrary:mergeReleaseNativeLibs
> Task :unityLibrary:stripReleaseDebugSymbols
> Task :unityLibrary:copyReleaseJniLibsProjectOnly
> Task :launcher:mergeReleaseAssets
> Task :launcher:processReleaseManifest
> Task :launcher:processReleaseResources
> Task :launcher:javaPreCompileRelease
> Task :launcher:compileReleaseJavaWithJavac
> Task :launcher:compileReleaseSources
> Task :launcher:lintVitalRelease
WARNING: The targetSdk version should not be declared in the android manifest file. You can move the version from the manifest to the defaultConfig in the build.gradle file.
WARNING: The targetSdk version should not be declared in the android manifest file. You can move the version from the manifest to the defaultConfig in the build.gradle file.
> Task :launcher:dexBuilderRelease
> Task :launcher:mergeReleaseNativeLibs
> Task :launcher:stripReleaseDebugSymbols
> Task :launcher:mergeDexRelease
> Task :launcher:mergeReleaseJavaResource
> Task :launcher:packageRelease
> Task :launcher:packageRelease FAILED
68 actionable tasks: 68 executed
]
exit code: 1
于是去谷歌搜索了下,也没找到跟这一模一样的错误信息,尝试着改了gradle.properties改了gradle版本从3.6.3改成3.4.0,报错改了,变成了
Execution failed for task ':launcher:packageRelease'.
> 1 exception was raised by workers:
java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: value (4295634145) > 0x00000000ffffffffL
然后再尝试着打开multiDexEnable,发现也是不行。
multiDexEnabled true
将IL2CPP取消掉也不行,加上keystore签名也不行(之前成功的没有加)
导出Android工程出包,也是一样报错。。。这事情太诡异了。
自从Unity从2019版本开始将安卓打包系统Internal System移除,只能通过Gradle打包,这点真的太不方便了,Gradle打包总是莫名其妙各种打包问题。
之前碰到过,通过还原ProjectSetting修好了(之前打包不知道为什么会自动修改ProjectSetting),但是这次又不行了,实在是不知道什么原因。
如果有朋友知道怎么解决的,欢迎评论告诉我,感谢。
-----------------------------------------------------------------------------
更新:2021.12.5
经过测试,删除StreamingAssets下的.mp3、.mp4素材,可以正常打包。说明应该是StreamingAssets某些文件扩展名不支持,会导致报错,具体看这个链接提到的unity bug。
------------------------------------------------------------------------------
更新:20220311
今天又开始报错了,删了一些文件还是报错,最后继续删才能打包,猜测很大的可能是因为包体超过了4G。似乎apk超过4G打包会报错。
Bug: 4GB limit to Textures in standalone build - Unity Forum
-----------------------------------------------------------------------------
【Unity】打包报错 com.android.buil.gradle.internal.tasks.workers$ActionFacade
unity3d - How to fix error "A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade" after installing Photon in Unity - Stack Overflowunity3d - How to fix in Unity "A failure occurred while executing com.android.build.gradle.internal.tasks.workers$actionfacade" - Stack Overflow
Unity 报错之 接入YomboTGSDK后打包报错:mainTemplate.gradle needs to be updated(property ‘unityStreamingAssets‘)
Unity 报错之 接入YomboTGSDK后打包报错:mainTemplate.gradle needs to be updated!
一,遇到问题
1.1 问题背景
产生问题:Unity2021.x版本接入YomboTGSDK,SDK版本1.9.4,导入SDK后打安卓包遇到报错。
解决过程:一开始以为解决给报错不是简简单单,况且我之前还在Unity2019版本接入过1.9.0版本的SDK。万万没想到,我周日用了一下午的时间也没有解决这个问题。
求助大佬:最后还是到公司求助大佬,在大佬的帮助下得以解决。以此文记录一下解决过程,致敬大佬。
1.2 报错日志
报错如下:
报错日志:
mainTemplate.gradle needs to be updated!
We’ve detected that your custom mainTemplate.gradle file is using the old android application format and needs to be upgraded to function as an android library. We can try to do this automatically, your current mainTemplate.gradle file will be backed up. Continue?
翻译:
我们已经检测到您的自定义主模板。Gradle文件使用的是旧的android应用程序格式,需要升级为android库的功能。我们可以尝试自动做到这一点,你当前的主模板。Gradle文件将被备份。继续吗?
二,尝试解决
2.1 自动修复
我觉得看到1.2上面弹窗提示的第一反应是点:“Yes”,让编辑器为我们自动修复,结果大概率是不行的,我这边选择“Yes”后,打包失败,得到的报错:
2.2 取消勾选
把报错相关的Gradle在Player面上取消勾选。
尝试后,解决失败。
PS:后知后觉接入SDK是需要修改自定义这个Gradle的,所以根本就不能以这种方式进行解决。
三,解决问题
3.1 步骤一:
此步骤是在网上搜到的大多数的解决方案,此部分参考自:Unity打Android包,报.gradle needs to be updated,old aaptOptions noCompress,需要更新unityStreamingAssets的错误
提示mainTemplate.gradle需要更新。这里我们把: Assets/Plugins/Android \'mainTemplate.gradle
aaptOptions
noCompress = [\'.unity3d\', \'.ress\', \'.resource\', \'.obb\'**STREAMING_ASSETS**]
ignoreAssetsPattern = "!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~"
**SIGN**
修改为
aaptOptions
noCompress = [\'.ress\', \'.resource\', \'.obb\'] + unityStreamingAssets.tokenize(\', \')
ignoreAssetsPattern = "!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~"
**SIGN**
‘launcherTemplate.gradle’ 也同样将里面的
noCompress = [\'.unity3d\', \'.ress\', \'.resource\', \'.obb\'**STREAMING_ASSETS**]
替换为
noCompress = [\'.ress\', \'.resource\', \'.obb\'] + unityStreamingAssets.tokenize(\', \')
替换完成即可尝试重新打包,若打包还未成功,收到如下报错:
请在此基础上,继续往下看3.2 步骤二。
3.2 步骤二:
在第二条报错中可以看到:
报错代码在:
Build file \'/Users/czhenya/Projects/TGSDK/Library/Bee/Android/Prj/IL2CPP/Gradle/launcher/build.gradle\' line: 30
打开文件一看:
这个就是3.1步骤一中修改的配置。
后面报错:无法为com.android.build.gradle.internal.dsl.AaptOptions的对象获得未知属性’unityStreamingAssets’。
看到这里我还是不知道该怎么去修改,直到看到安卓工程中的gradle文件:
我想起来SDK有一个打包配置脚本,在脚本中添加了writer.WriteLine("unityStreamingAssets=.unity3d,.bundle");
。 然后就打包成功了。
配置脚本完整代码如下:
using UnityEditor;
using UnityEditor.Android;
using UnityEngine;
using System.IO;
public class TGSDKAndroidBuildProcessor : IPostGenerateGradleAndroidProject
public int callbackOrder
// 同种插件的优先级
get return 999;
public void OnPostGenerateGradleAndroidProject(string path)
Debug.Log("Bulid path : " + path);
#if UNITY_2019_3_OR_NEWER
string gradlePropertiesFile = path + "/../gradle.properties";
#else
string gradlePropertiesFile = path + "/gradle.properties";
#endif
if (File.Exists(gradlePropertiesFile))
File.Delete(gradlePropertiesFile);
StreamWriter writer = File.CreateText(gradlePropertiesFile);
writer.WriteLine("org.gradle.jvmargs=-Xmx4096M");
writer.WriteLine("android.useAndroidX=true");
writer.WriteLine("android.enableJetifier=true");
writer.WriteLine("unityStreamingAssets=.unity3d,.bundle");
writer.Flush();
writer.Close();
解决方法:首先按照3.1中,修改两个Gradle中的配置。然后在找到(没有可以创建一个)安卓打包配置脚本,添加unityStreamingAssets
这项。
四,小结
-
遇到问题的原因:Unity升级导致打安卓包的设置变了。
若你同时打包过2019版本和2021版本,你会发现两个版本的Unity导出的安卓工程目录都是不一样的:
-
解决问题的方法:大家都知道需要按照报错提示去解决,重点是要找到报错关键所在,这样才能更快更准的解决问题。
比如:在3.1步骤中的报错,我首先关注的是下图选中的这一行,其实报错关键点在下面Gradle build faled这个错误信息里。
这也是我花费了大量时间,还没有解决问题的主要原因。
希望本片文章可以帮助你解决问题的同时,也能给你带来一些解决方案的提示。
以上是关于Unity打包报错A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFa的主要内容,如果未能解决你的问题,请参考以下文章
记一次Jenkins 打包异常 ERROR: Exception when publishing, exception message [Failure]
Unity 报错之 打包安卓闪退 Could not allocate memory: System out of memory
Unity 报错之 打包安卓闪退 Could not allocate memory: System out of memory
一打开unity就会有报错,导致assetbundle不能打包(没有诸如BuildAssetBundle之类的选项)
Unity打包报错 com.android.buil.gradle.internal.tasks.workers$ActionFacade
Unity 报错之 接入YomboTGSDK后打包报错:mainTemplate.gradle needs to be updated(property ‘unityStreamingAssets‘)