Unity 2017.3 and Unity 2018 – Gradle build failed

Tl;dr: We got a CommandInvocationFailure when trying to build from unity 2017 and 2018 to an android device. The reason turned out to be that our password contained single quotes: ‘. The build.gradle stores the password in an unescaped string defined with single quotes and was therefor broken by our password.

Temporary solution: change password to something without any quotes or build from android studio and change the strings single quotes to double quotes.

We have reported this as a bug to unity.

The long version

We were really confused about this error at first. “CommandInvokationFailure: Gradle build failed.”


CommandInvokationFailure: Gradle build failed.
C:/Program Files/Java/jdk1.8.0_111\bin\java.exe -classpath "C:\Program Files\Unity 2018.1.0b4\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\gradle\lib\gradle-launcher-4.0.1.jar" org.gradle.launcher.GradleMain "-Dorg.gradle.jvmargs=-Xmx2048m" "assembleRelease"

stderr[

FAILURE: Build failed with an exception.

* Where:
Build file ‘F:\AFAB\BallongHogt\BallongHogt\Temp\gradleOut\build.gradle’ line: 144

* What went wrong:
Could not compile build file ‘F:\AFAB\BallongHogt\BallongHogt\Temp\gradleOut\build.gradle’.
> startup failed:
build file ‘F:\AFAB\BallongHogt\BallongHogt\Temp\gradleOut\build.gradle’: 144: unexpected char: ”’ @ line 144, column 81.
partsOfOurPasswordHere’AndalsoHere’
^

1 error

* Try:
Run with –stacktrace option to get the stack trace. Run with –info or –debug option to get more log output.

BUILD FAILED in 1s
]
stdout[

]
exit code: 1
UnityEditor.Android.Command.WaitForProgramToRun (UnityEditor.Utils.Program p, UnityEditor.Android.WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg)
UnityEditor.Android.Command.Run (System.Diagnostics.ProcessStartInfo psi, UnityEditor.Android.WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg)
UnityEditor.Android.AndroidJavaTools.RunJava (System.String args, System.String workingdir, System.Action`1 progress, System.String error)
UnityEditor.Android.GradleWrapper.Run (System.String workingdir, System.String task, System.Action`1 progress)
Rethrow as GradleInvokationException: Gradle build failed
UnityEditor.Android.GradleWrapper.Run (System.String workingdir, System.String task, System.Action`1 progress)
UnityEditor.Android.PostProcessor.Tasks.BuildGradleProject.Execute (UnityEditor.Android.PostProcessor.PostProcessorContext context)
UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

We checked the “Export Project” checkbox and tried to compile the project with android studio which also referred to build.Gradle so we opened it with android studio and saw more clearly with the syntax highlighting that the password was cut off by it having a single quote in the middle of the password.

One way to solve this issue is to change the password to not contain quotes but we hope Unity will work around this somehow and make it possible to use passwords with quotes. So for now we’re satisfied with building our app from android studio and manually changing storePassword and keyPassword to wrap the string with double quotes.