1

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 the Temp 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 tried gradle 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
7
  • Thanks @IntelliJAmiya but unfortunately I'm working with Unity, not IntelliJ or Android Studio, so most of those answers don't even apply to my problem May 2, 2018 at 13:28
  • Are you using any plugins in your Unity project? If so, can you list them?
    – Programmer
    May 2, 2018 at 13:45
  • Hi @Programmer Nope, I'm not using any plugins (yet) May 2, 2018 at 13:49
  • Ok, check back for my answer in few minuets.
    – Programmer
    May 2, 2018 at 13:50

1 Answer 1

1

The most important part of the error is:

If using the gradle wrapper, try editing the distributionUrl in [...]/UnityProject/Temp/gradleOut/gradle/wrapper/gradle-wrapper.properties to gradle-2.10-all.zip

It wants you to use gradle-2.10.

1.Go to <UnityInstallationDirecory>\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\GradleTemplates, then copy mainTemplate.gradle file to your <ProjectName>Assets\Plugins\Android folder.

2. Open the mainTemplate.gradle file you copied to the <ProjectName>Assets\Plugins\Android folder.

3.Find classpath 'com.android.tools.build:gradle:2.3.0' inside it.

Replace the gradle:2.3.0 with the version the error is asking you to replace it to.

In your case, that should be gradle:2.1.0 then save it.

3
  • The-same error? Can you add a screenshot to show where you put the mainTemplate file in your project?
    – Programmer
    May 2, 2018 at 14:58
  • It's under UnityProject/Assets/Plugins/Android as you can see here s7.postimg.cc/5uo47nm6j/Screen_Shot.png May 2, 2018 at 15:14
  • You said you are not using plugin but there seems to be plugins in that folder. There is libs folder and other files which are blurred out and you also have a manifest file there. Those can be modifying your gradle file.
    – Programmer
    May 2, 2018 at 16:31

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.