com.android.builder.internal.aapt.v2.Aapt2InternalException: AAPT2 aapt2-3.4.0-5326820-windows Daemon : Daemon startup failed

I try to build Unity project to Android platform via Jenkins.
When I build the project in Unity Editor, it works well - succesfully get my APK.
But if I build the same project in same condition on CLI, it always occurs error like below.

****CommandInvokationFailure: Gradle build failed.
C:/Program Files/Unity/Hub/Editor/2019.2.6f1/Editor/Data/PlaybackEngines/AndroidPlayer/Tools\OpenJDK\Windows\bin\java.exe -classpath "C:\Program Files\Unity\Hub\Editor\2019.2.6f1\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\gradle\lib\gradle-launcher-5.6.3.jar" org.gradle.launcher.GradleMain "-Dorg.gradle.jvmargs=-Xmx4096m" "assembleRelease"

stderr[

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':mergeReleaseResources'.
> 8 exceptions were raised by workers:
com.android.builder.internal.aapt.v2.Aapt2InternalException: AAPT2 aapt2-3.4.0-5326820-windows Daemon #0: Daemon startup failed
This should not happen under normal circumstances, please file an issue if it does.
com.android.builder.internal.aapt.v2.Aapt2InternalException: AAPT2 aapt2-3.4.0-5326820-windows Daemon #1: Daemon startup failed
This should not happen under normal circumstances, please file an issue if it does.
com.android.builder.internal.aapt.v2.Aapt2InternalException: AAPT2 aapt2-3.4.0-5326820-windows Daemon #2: Daemon startup failed
This should not happen under normal circumstances, please file an issue if it does.
com.android.builder.internal.aapt.v2.Aapt2InternalException: AAPT2 aapt2-3.4.0-5326820-windows Daemon #3: Daemon startup failed
This should not happen under normal circumstances, please file an issue if it does.
com.android.builder.internal.aapt.v2.Aapt2InternalException: AAPT2 aapt2-3.4.0-5326820-windows Daemon #4: Daemon startup failed
This should not happen under normal circumstances, please file an issue if it does.
com.android.builder.internal.aapt.v2.Aapt2InternalException: AAPT2 aapt2-3.4.0-5326820-windows Daemon #5: Daemon startup failed
This should not happen under normal circumstances, please file an issue if it does.
com.android.builder.internal.aapt.v2.Aapt2InternalException: AAPT2 aapt2-3.4.0-5326820-windows Daemon #6: Daemon startup failed
This should not happen under normal circumstances, please file an issue if it does.
com.android.builder.internal.aapt.v2.Aapt2InternalException: AAPT2 aapt2-3.4.0-5326820-windows Daemon #7: Daemon startup failed
This should not happen under normal circumstances, please file an issue if it does.

* 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](https://help.gradle.org/)

BUILD FAILED in 25s
]
stdout[
> Task ![:p](https://forum.unity.com/styles/default/xenforo/clear.png "Stick Out Tongue :p")reBuild UP-TO-DATE
> Task ![:p](https://forum.unity.com/styles/default/xenforo/clear.png "Stick Out Tongue :p")reReleaseBuild
> Task :compileReleaseAidl NO-SOURCE
> Task :compileReleaseRenderscript NO-SOURCE
> Task :checkReleaseManifest
> Task :generateReleaseBuildConfig
> Task ![:p](https://forum.unity.com/styles/default/xenforo/clear.png "Stick Out Tongue :p")repareLintJar
> Task :generateReleaseSources
> Task :javaPreCompileRelease
> Task :mainApkListPersistenceRelease
> Task :generateReleaseResValues
> Task :generateReleaseResources
> Task :mergeReleaseResources FAILED
8 actionable tasks: 8 executed
]
exit code: 1
UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
JENKINS.AutoBuilder:GenericBuild(String[], String, BuildTargetGroup, BuildTarget, BuildOptions) (at Assets\AutoBuilder.cs:94)
JENKINS.AutoBuilder![:p](https://forum.unity.com/styles/default/xenforo/clear.png "Stick Out Tongue :p")erformBuildAndroid() (at Assets\AutoBuilder.cs:37)

Does anyone experience this kind of error before?
I’ll apperciate if someone reply me with a solution how to resolve the error.
Version of Unity I’m using is “Unity 2019.2.6f” and Gradle version is 5.6.3.

Thanks.

1 Like

Hi,

I am also facing the same problem, do you have a solution?

1 Like

I am also facing the same problem. my Unity version is 2018.4.9f1.
There was no problem in the 2018.3.5f1 version.
There seems to be a compatibility issue with Gradle 5.1.1 version

I’m still suffered from the issue.
@ho-dragon Gradle version I’m using to build is 5.6.1. I replaced Unity’s default Gradle(5.1.1) to 5.6.1 version, but still get the same error.

I’ve tried many solutions from other forums, but always get the same error message.
Today, I just begin to have a doubt that the issue caused by Jenkins build environment. Because the message “Daemon startup failed” seems like Jenkins has a problem with launching Gradle daemon.

By the way, anyone who resolve the issue, please reply the thread. It’ll save my day. Thanks.

I am using Jenkins. I also suspect the Jenkins Unity plugin. I am trying various things to solve the problem. I’ll let you know if you find it.

I have found a solution.
But I don’t know if this solution is perfect.
Open the ‘mainTemplate.gradle’ file in a text editor and change build.gradle3.4.0 version to 3.2.0.

‘mainTemplate.gradle’ Path is
“C:\Program Files\Unity2018.4.9f1\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\GradleTemplates\mainTemplate.gradle”

dependencies {
    classpath 'com.android.tools.build:gradle:3.4.0'}

Change it like below

dependencies {
    classpath 'com.android.tools.build:gradle:3.2.0'}

I will be happy if it helps you.

I set the classpath value as you wrote above, but still it emit the same error. Anyway thanks to your advice @ho-dragon

Besides your solution, I found another solution to fix the issue.

  1. In my Unity auto build script, I set like
    buildPlayerOptions.options = BuildOptions.AcceptExternalModificationsToPlayer;.
    The option I set means that I’ll export the Unity project as gradle build project.
  2. After fixing my autobuild script, I set Gradle build workflow on my Jenkins just after Unity build plugin with options like below image.

Now Jenkins works like below steps.

  1. Export Gradle build project from Unity
  2. Build Gradle project and create release APK.

It works at last!!!

Still I definitely don’t have any idea why internal Unity Gradle build fails in Jenkins, but I’m relieved to find the way to bypass the issue.

Thanks.

1 Like

Hi @zootyducky,

I’m facing a similar issue. Would you mind sending me, or attaching here some documentation regarding the first and second step, anything that can give me more info in regards on how to setup the build options in regards to the unity context and the above issue.
I’m a bit nervous in regards of building with gradle, judging by the screenshot you’ve attached, I see that you only attached one task in the gradle pipeline script, is this enough is that command the usual one, or is some custom command?

Thanks

Hi @zootyducky
I tried your solution with my gradle version is 5.4.1
I use the Gradle Plugin in jenkins,and build success,but I don’t found my apk either in jenkins workspace or gradle install location or C:\Users\xxx\.gradle

I use Unity 2019.4.3f1, build android apk in jenkins tooks me 4 days, this problem comfused me for 2 days, can you help me find my apk file?
thanks.

My English is not very well, thanks reading