I'm building a game for Android in Unity on OS X and I get this error.
CommandInvokationFailure: Gradle build failed.
/Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home/bin/java -classpath "/Applications/Unity/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 '[...]/UnityProject/Temp/gradleOut/build.gradle' line: 19
* What went wrong:
A problem occurred evaluating root project 'gradleOut'.
> Failed to apply plugin [id 'com.android.application']
> Gradle version 2.10 is required. Current version is 4.0.1. If using the gradle wrapper, try editing the distributionUrl in [...]/UnityProject/Temp/gradleOut/gradle/wrapper/gradle-wrapper.properties to gradle-2.10-all.zip
* 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)
Unity uses Gradle version 2.10 but apparently current version is 4.0.1 (Does this mean that my PC has defined a "default" gradle version somewhere?)
EDIT (3rd May)
I managed to export the project, open it with Android Studio and there I could force gradle version 2.10 and Android plugin version 2.1.0 This way the project compiled and I was able to execute it on device.
Is there a way I can do something similar to this on Unity? or system-wide?
What I've done so far (without success)
- As suggested I looked for the file
gradle-wrapper.properties
but it does not exist, and since it's under theTemp
folder it wasn't a very promising path. - I tried to create such file and configure the
distributionUrl
as stated. - Did
brew install gradle
and then on project's folder I triedgradle wrapper --gradle-version 2.10
- Uninstall Unity, delete
~/.gradle
folder. Reinstall Unity. - Tried to install gradle using SDKMAN! (this also sets Gradle 2.10 as default)
My specific scenario
- Unity 2017.4.2f2
- macOS Sierra
That's pretty much everything, any ideas?
Thanks!
EDITS
- Added more unsuccessful attempts
- Added the full error