Unity 2019.2.9f1 Android: Gradle build failed

Hi!
Since I upgraded from 2019.2.6 to 2019.2.7 Unity doesn’t want to compile for android anymore.
I’m getting a Build Failure window with “Gradle build failed, see the console for details”
I have now upgraded to 2019.2.9f1 and still having the same issue.

I’m using the Android SDK and NDK installed with unity.
I don’t have any other android sdk or ndk installation.
Things were working correctly with 2019.2.6

I have uninstalled Unity and the Unity hub then reinstalled them.
I have deleted any “.android” or “.gradle” folder I have found in the “appdata” folder after uninstalling.
I’m getting mad. :rage:

Anyone can help?

That’s what the console says:

UnityEditor.EditorApplication:Internal_CallGlobalEventHandler() (at C:/buildslave/unity/build/Editor/Mono/EditorApplication.cs:432)
FAILURE: Build failed with an exception.

UnityEditor.EditorApplication:Internal_CallGlobalEventHandler() (at C:/buildslave/unity/build/Editor/Mono/EditorApplication.cs:432)


UnityEditor.EditorApplication:Internal_CallGlobalEventHandler() (at C:/buildslave/unity/build/Editor/Mono/EditorApplication.cs:432)
* Where:

UnityEditor.EditorApplication:Internal_CallGlobalEventHandler() (at C:/buildslave/unity/build/Editor/Mono/EditorApplication.cs:432)
Build file 'C:\UnityProjects\game\Temp\gradleOut\build.gradle' line: 47

UnityEditor.EditorApplication:Internal_CallGlobalEventHandler() (at C:/buildslave/unity/build/Editor/Mono/EditorApplication.cs:432)


UnityEditor.EditorApplication:Internal_CallGlobalEventHandler() (at C:/buildslave/unity/build/Editor/Mono/EditorApplication.cs:432)
* What went wrong:

UnityEditor.EditorApplication:Internal_CallGlobalEventHandler() (at C:/buildslave/unity/build/Editor/Mono/EditorApplication.cs:432)
A problem occurred evaluating root project 'gradleOut'.

UnityEditor.EditorApplication:Internal_CallGlobalEventHandler() (at C:/buildslave/unity/build/Editor/Mono/EditorApplication.cs:432)
> Cannot invoke method minus() on null object

UnityEditor.EditorApplication:Internal_CallGlobalEventHandler() (at C:/buildslave/unity/build/Editor/Mono/EditorApplication.cs:432)


UnityEditor.EditorApplication:Internal_CallGlobalEventHandler() (at C:/buildslave/unity/build/Editor/Mono/EditorApplication.cs:432)
* Try:

UnityEditor.EditorApplication:Internal_CallGlobalEventHandler() (at C:/buildslave/unity/build/Editor/Mono/EditorApplication.cs:432)
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.

UnityEditor.EditorApplication:Internal_CallGlobalEventHandler() (at C:/buildslave/unity/build/Editor/Mono/EditorApplication.cs:432)


UnityEditor.EditorApplication:Internal_CallGlobalEventHandler() (at C:/buildslave/unity/build/Editor/Mono/EditorApplication.cs:432)
* Get more help at https://help.gradle.org

UnityEditor.EditorApplication:Internal_CallGlobalEventHandler() (at C:/buildslave/unity/build/Editor/Mono/EditorApplication.cs:432)


UnityEditor.EditorApplication:Internal_CallGlobalEventHandler() (at C:/buildslave/unity/build/Editor/Mono/EditorApplication.cs:432)
BUILD FAILED in 1s

UnityEditor.EditorApplication:Internal_CallGlobalEventHandler() (at C:/buildslave/unity/build/Editor/Mono/EditorApplication.cs:432)


UnityEditor.EditorApplication:Internal_CallGlobalEventHandler() (at C:/buildslave/unity/build/Editor/Mono/EditorApplication.cs:432)
> Configure project :

UnityEditor.EditorApplication:Internal_CallGlobalEventHandler() (at C:/buildslave/unity/build/Editor/Mono/EditorApplication.cs:432)
Exception while marshalling C:\Program Files\Unity\Hub\Editor\2019.2.9f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\build-tools\28.0.3\package.xml. Probably the SDK is read-only

UnityEditor.EditorApplication:Internal_CallGlobalEventHandler() (at C:/buildslave/unity/build/Editor/Mono/EditorApplication.cs:432)
Exception while marshalling C:\Program Files\Unity\Hub\Editor\2019.2.9f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\platform-tools\package.xml. Probably the SDK is read-only

UnityEditor.EditorApplication:Internal_CallGlobalEventHandler() (at C:/buildslave/unity/build/Editor/Mono/EditorApplication.cs:432)
Exception while marshalling C:\Program Files\Unity\Hub\Editor\2019.2.9f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\platforms\android-28\package.xml. Probably the SDK is read-only

UnityEditor.EditorApplication:Internal_CallGlobalEventHandler() (at C:/buildslave/unity/build/Editor/Mono/EditorApplication.cs:432)
Exception while marshalling C:\Program Files\Unity\Hub\Editor\2019.2.9f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\tools\package.xml. Probably the SDK is read-only

UnityEditor.EditorApplication:Internal_CallGlobalEventHandler() (at C:/buildslave/unity/build/Editor/Mono/EditorApplication.cs:432)
Exception while marshalling C:\Program Files\Unity\Hub\Editor\2019.2.9f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\build-tools\28.0.3\package.xml. Probably the SDK is read-only

UnityEditor.EditorApplication:Internal_CallGlobalEventHandler() (at C:/buildslave/unity/build/Editor/Mono/EditorApplication.cs:432)
Exception while marshalling C:\Program Files\Unity\Hub\Editor\2019.2.9f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\platform-tools\package.xml. Probably the SDK is read-only

UnityEditor.EditorApplication:Internal_CallGlobalEventHandler() (at C:/buildslave/unity/build/Editor/Mono/EditorApplication.cs:432)
Exception while marshalling C:\Program Files\Unity\Hub\Editor\2019.2.9f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\platforms\android-28\package.xml. Probably the SDK is read-only

UnityEditor.EditorApplication:Internal_CallGlobalEventHandler() (at C:/buildslave/unity/build/Editor/Mono/EditorApplication.cs:432)
Exception while marshalling C:\Program Files\Unity\Hub\Editor\2019.2.9f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\tools\package.xml. Probably the SDK is read-only

UnityEditor.EditorApplication:Internal_CallGlobalEventHandler() (at C:/buildslave/unity/build/Editor/Mono/EditorApplication.cs:432)
CommandInvokationFailure: Gradle build failed.
C:/Program Files/Unity/Hub/Editor/2019.2.9f1/Editor/Data/PlaybackEngines/AndroidPlayer/Tools\OpenJDK\Windows\bin\java.exe -classpath "C:\Program Files\Unity\Hub\Editor\2019.2.9f1\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\gradle\lib\gradle-launcher-5.1.1.jar" org.gradle.launcher.GradleMain "-Dorg.gradle.jvmargs=-Xmx4096m" "assembleRelease"

stderr[

FAILURE: Build failed with an exception.

* Where:
Build file 'C:\UnityProjects\game\Temp\gradleOut\build.gradle' line: 47

* What went wrong:
A problem occurred evaluating root project 'gradleOut'.
> Cannot invoke method minus() on null object

* 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 1s
]
stdout[

> Configure project :
Exception while marshalling C:\Program Files\Unity\Hub\Editor\2019.2.9f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\build-tools\28.0.3\package.xml. Probably the SDK is read-only
Exception while marshalling C:\Program Files\Unity\Hub\Editor\2019.2.9f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\platform-tools\package.xml. Probably the SDK is read-only
Exception while marshalling C:\Program Files\Unity\Hub\Editor\2019.2.9f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\platforms\android-28\package.xml. Probably the SDK is read-only
Exception while marshalling C:\Program Files\Unity\Hub\Editor\2019.2.9f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\tools\package.xml. Probably the SDK is read-only
Exception while marshalling C:\Program Files\Unity\Hub\Editor\2019.2.9f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\build-tools\28.0.3\package.xml. Probably the SDK is read-only
Exception while marshalling C:\Program Files\Unity\Hub\Editor\2019.2.9f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\platform-tools\package.xml. Probably the SDK is read-only
Exception while marshalling C:\Program Files\Unity\Hub\Editor\2019.2.9f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\platforms\android-28\package.xml. Probably the SDK is read-only
Exception while marshalling C:\Program Files\Unity\Hub\Editor\2019.2.9f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\tools\package.xml. Probably the SDK is read-only
]
exit code: 1
UnityEditor.Android.Command.WaitForProgramToRun (UnityEditor.Utils.Program p, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <24d9b022aa584914af833273ea899103>:0)
UnityEditor.Android.Command.Run (System.Diagnostics.ProcessStartInfo psi, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <24d9b022aa584914af833273ea899103>:0)
UnityEditor.Android.Command.Run (System.String command, System.String args, System.String workingdir, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <24d9b022aa584914af833273ea899103>:0)
UnityEditor.Android.AndroidJavaTools.RunJava (System.String args, System.String workingdir, System.Action`1[T] progress, System.String error) (at <24d9b022aa584914af833273ea899103>:0)
UnityEditor.Android.GradleWrapper.Run (UnityEditor.Android.AndroidJavaTools javaTools, System.String workingdir, System.String task, System.Action`1[T] progress) (at <24d9b022aa584914af833273ea899103>: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 <24d9b022aa584914af833273ea899103>:0)
UnityEditor.Android.PostProcessor.Tasks.BuildGradleProject.Execute (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <24d9b022aa584914af833273ea899103>:0)
UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <24d9b022aa584914af833273ea899103>: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 <24d9b022aa584914af833273ea899103>:0)
UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <24d9b022aa584914af833273ea899103>: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 <24d9b022aa584914af833273ea899103>:0)
UnityEditor.Android.AndroidBuildPostprocessor.PostProcess (UnityEditor.Modules.BuildPostProcessArgs args, UnityEditor.BuildProperties& outProperties) (at <24d9b022aa584914af833273ea899103>: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 C:/buildslave/unity/build/Editor/Mono/BuildPipeline/PostprocessBuildPlayer.cs:281)
UnityEditor.EditorApplication:Internal_CallGlobalEventHandler() (at C:/buildslave/unity/build/Editor/Mono/EditorApplication.cs:432)
Build completed with a result of 'Failed'
UnityEditor.EditorApplication:Internal_CallGlobalEventHandler() (at C:/buildslave/unity/build/Editor/Mono/EditorApplication.cs:432)
UnityEditor.BuildPlayerWindow+BuildMethodException: 28 errors
  at UnityEditor.BuildPlayerWindow+DefaultBuildMethods.BuildPlayer (UnityEditor.BuildPlayerOptions options) [0x00242] in C:\buildslave\unity\build\Editor\Mono\BuildPlayerWindowBuildMethods.cs:190
  at UnityEditor.BuildPlayerWindow.CallBuildMethods (System.Boolean askForBuildLocation, UnityEditor.BuildOptions defaultBuildOptions) [0x0007f] in C:\buildslave\unity\build\Editor\Mono\BuildPlayerWindowBuildMethods.cs:95
UnityEditor.EditorApplication:Internal_CallGlobalEventHandler() (at C:/buildslave/unity/build/Editor/Mono/EditorApplication.cs:432)

Aaaand of course, after spending hours with this, losing hope and posting this here I found the issue myself :stuck_out_tongue:
The problem was that I recently installed a neat script from the store named “AutoVersion”
This asset keeps track of the amount of builds you did and changes your app version accordingly.
The problem is it defaults to -1 version number and it turns out that Gradle doesn’t like AT ALL your version number to be less or equal to zero.
So if anyone is having this issue in the future, double check your app Version on the player settings is greater than zero AND the Bundle Version Code is at least 1. Otherwise Gradle will refuse to build and will not tell you why! :roll_eyes:
Anyway, it’s working now :stuck_out_tongue:

7 Likes

hi atomicjoe , it solved the issue. Thanks.

1 Like

wow, this is exactly what happened to me. Thanks for sharing your find!

1 Like