Gradle Build Error: Gradle version 2.10 is required. Current version is 4.0.1

I can’t build for android with gradle it says that I’m using the wrong version, where do I change it so it uses the right version?

Or is it something else?

Hi!

Are you using a custom mainTemplate.gradle ? It might be still trying to use an older android gradle plugin which doesn’t work with gradle 4.0.1. If you’re not using a custom template, could you please send us a bug report?

Hi,

I’ve also come into this issue when updating to Unity 2017.3.0f3. I do use a custom template gradle file (which works fine in 2017.2), my template does specify gradle:2.1.2 but doesn’t seem to be respected, I’ve attached my full mainTemplate.gradle file.

I do also set my GRADLE_HOME environment variable to a directory with gradle-4.3.1 which may be causing issue, but I use this elsewhere with Android Studio so don’t want to change it.

Is there a place in unity to set the gradle version? I’m not totally sure where it gets it from to start with, but I presume the environment variable.

Thanks,
Dominic

Here’s my full error:

CommandInvokationFailure: Gradle build failed.
/Library/Java/JavaVirtualMachines/jdk1.8.0_92.jdk/Contents/Home/bin/java -classpath “/Volumes/Samsung_T5/Applications/Unity/PlaybackEngines/AndroidPlayer/Tools/gradle/lib/gradle-launcher-4.0.1.jar” org.gradle.launcher.GradleMain “-Dorg.gradle.jvmargs=-Xmx2048m” “assembleDebug”

stderr[

FAILURE: Build failed with an exception.

  • Where:
    Build file ‘/Volumes/Samsung_T5/Repositories/xxx/unity-sdk/plugin/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 /Volumes/Samsung_T5/Repositories/xxx/unity-sdk/plugin/Temp/gradleOut/gradle/wrapper/gradle-wrapper.properties to gradle-2.10-all.zip

@DomRoberts I think you’ll need to change your gradle version in your custom template file.
If you find the template gradle for your Unity version (Applications/Unity/PlaybackEngines/AndroidPlayer/Tools/GradleTemplates/mainTemplate.gradle on OSX for example), you can see the gradle version being used.
In Unity 2017.3.0f3 it’s gradle:2.3.0, so just update your custom file with that.
I’m not sure why it says the current version is 4.0.1 because the template seems to say otherwise. Either way, this worked for me.

2 Likes

Hallo.
Thank you about this information. It helps me do repair gradle buid in unity 2017.3.1p1
how can I identify current gradle version in unity?

3 Likes

It should be the one mentioned in the mainTemplate.gradle file as far as I know. Not sure where that path is on windows, but you can find it on OSX with the path I mentioned above. :slight_smile:

1 Like

Thanks @kiwipxl thats fixed it.

That saved my ass too, i changed to 4.0.1 according to the warning n didnt work. How a normal dev would know what gradle version 2017 uses!!! (We just upgraded to 2017 so 2.0.1 was totally fine before in 5.6)

Please don’t mix up Gradle version and Android plugin version.

What you specify in build.gradle by having

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

is the Android plugin version. (corresponds Android Studio version).
The Gradle binary itself is shipped with Unity, and you can’t change the version easily.

So:

2017.1 and 2017.2 use
Android plugin version 2.1.0
Gradle version 2.14

2017.4 up to and including 2017.4.16 uses
Android plugin version 2.3.0
Gradle version 4.0.1

2017.4 starting from 2017.4.17 uses
Android plugin version 3.2
Gradle version 4.6
(added support for building Android app bundles)

2018.1 uses
Android plugin version 2.3.0
Gradle version 4.0.1
2018.2 uses
Android plugin version 3.0.1
Gradle version 4.2.1
2018.3, 2018.4 up to and including 2018.4.3f1 and 2019.1 up to and including 2019.1.6f1 use
Android plugin version 3.2
Gradle version 4.6
2018.4 starting from 2018.4.4f1, 2019.1 starting from 2019.1.7f1, 2019.2 and 2019.3 use
Android plugin version 3.4
Gradle version 5.1.1

25 Likes

great! thx, it saved me!

Thanks for all the great info! Helped me immensely!

Updated the post with versions for 2018.3.

1 Like

After updading plugin version from 2.1.0 to 3.2 in gradle template i faced with this error

CommandInvokationFailure: Gradle build failed.
C:/Program Files/Java/jdk1.8.0_141\bin\java.exe -classpath "C:\Program Files\Unity 2018.3.0b5\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\gradle\lib\gradle-launcher-4.6.jar" org.gradle.launcher.GradleMain "-Dorg.gradle.jvmargs=-Xmx4096m" "assembleRelease"

stderr[

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'gradleOut'.
> Could not resolve all artifacts for configuration ':classpath'.
   > Could not find com.android.tools.build:gradle:3.2.
     Searched in the following locations:
         https://jcenter.bintray.com/com/android/tools/build/gradle/3.2/gradle-3.2.pom
         https://jcenter.bintray.com/com/android/tools/build/gradle/3.2/gradle-3.2.jar
     Required by:
         project :

* 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 13s
]
stdout[
Starting a Gradle Daemon, 1 stopped Daemon could not be reused, use --status for details
]
exit code: 1
UnityEditor.Android.Command.WaitForProgramToRun (UnityEditor.Utils.Program p, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <480e50343593457c94864bd38c09a2ca>:0)
UnityEditor.Android.Command.Run (System.Diagnostics.ProcessStartInfo psi, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <480e50343593457c94864bd38c09a2ca>:0)
UnityEditor.Android.Command.Run (System.String command, System.String args, System.String workingdir, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <480e50343593457c94864bd38c09a2ca>:0)
UnityEditor.Android.AndroidJavaTools.RunJava (System.String args, System.String workingdir, System.Action`1[T] progress, System.String error) (at <480e50343593457c94864bd38c09a2ca>:0)
UnityEditor.Android.GradleWrapper.Run (UnityEditor.Android.AndroidJavaTools javaTools, System.String workingdir, System.String task, System.Action`1[T] progress) (at <480e50343593457c94864bd38c09a2ca>: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 <480e50343593457c94864bd38c09a2ca>:0)
UnityEditor.Android.PostProcessor.Tasks.BuildGradleProject.Execute (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <480e50343593457c94864bd38c09a2ca>:0)
UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <480e50343593457c94864bd38c09a2ca>:0)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

Then after all fixes i’ve got this error

FileNotFoundException: Temp\gradleOut\build\outputs\apk\release\gradleOut-release.apk does not exist
System.IO.File.Move (System.String sourceFileName, System.String destFileName) (at <f2e6809acb14476a81f399aeb800f8f2>:0)
UnityEditor.Android.PostProcessor.Tasks.BuildGradleProject.Execute (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <37ed2f677a93461fa013cddc2cc869d2>:0)
UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <37ed2f677a93461fa013cddc2cc869d2>: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 <37ed2f677a93461fa013cddc2cc869d2>:0)
UnityEditor.Android.AndroidBuildPostprocessor.PostProcess (UnityEditor.Modules.BuildPostProcessArgs args, UnityEditor.BuildProperties& outProperties) (at <37ed2f677a93461fa013cddc2cc869d2>: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:287)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

@justtime I think your build.gradle is missing google() in dependencies section, next to jcenter().

Since Gradle binary ships with Unity, is there any plan to make this modular and able to change it through settings or something? So we don’t have to update a Unity version just for gradle versions

1 Like

We are planning that. However, why would you need to update gradle itself?

Thanks Yury for your answer.
In the company we are providing different packages and different gradles version in Unity force us to create several mainTemplate. Perhaps with the possibility of choosing gradle version would be nice. It’s not a big trouble.

That’s valuable feedback, thank you @Martin_Gonzalez !

1 Like

I am getting this error

  • What went wrong:
    A problem occurred evaluating root project ‘gradleOut’.

Failed to apply plugin [id ‘com.android.application’]
Minimum supported Gradle version is 4.4. Current version is 4.2.1. If using the gradle wrapper, try editing the distributionUrl in…

My unity version is 2018.2.17f (the latest one) and I used 3.0.1 like you said but still was getting gradle errors… then I tried 3.1.0 it took more time then other build but this time I am facing this…
Please help

Is there any documentation page that contains this information? If not, it’d be nice to have this is the Unity docs.

2 Likes