Unity error during android apk build : Gradle build Failed

I am trying to build an apk file with Unity 2017.30f3 (64bit) on a Windows 10 PC. I get the following errors in the console:
-ERROR 1
CommandInvokationFailure: Gradle build failed.
C:/Program Files/Java/jdk1.8.0_152\bin\java.exe -classpath “C:\Program Files\Unity\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\gradle\lib\gradle-launcher-4.0.1.jar” org.gradle.launcher.GradleMain “-Dorg.gradle.jvmargs=-Xmx2048m” “assembleRelease”

-ERROR 2
Error building Player: 2 errors

-ERROR 3
Build completed with a result of ‘Failed’
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

-ERROR 4
UnityEditor.BuildPlayerWindow+BuildMethodException: 3 errors
at UnityEditor.BuildPlayerWindow+DefaultBuildMethods.BuildPlayer (BuildPlayerOptions options) [0x0020e] in C:\buildslave\unity\build\Editor\Mono\BuildPlayerWindowBuildMethods.cs:181
at UnityEditor.BuildPlayerWindow.CallBuildMethods (Boolean askForBuildLocation, BuildOptions defaultBuildOptions) [0x00065] in C:\buildslave\unity\build\Editor\Mono\BuildPlayerWindowBuildMethods.cs:88
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

I tried to solve as per suggetions from different forums but have not been able to solve it.
I have replaced the tools in the sdk with old tools, tried with jdk 8 instead of 9, restarted unity, reimported the project, but the problem persists. Been stuck at this for a long time. Please folks, all help is appreciated. Thanks.

Nice then! for next class, i recommend you to learn about FixedUpdate (like update fucntion, but is executed before the Ontrigger functions) This way, you can set some variables in FixedUpdate, that can be changed right ater at OnTrigger functions, each frame. This is good when using Trigger Enter and exit functions is not the solution. Bye!

1 Answer

1

Try to use gradle 2.3.0 instead of 2.1.0 or 4.0.1
You need to edit file mainTemplate.gradle in project folder \Assets\Plugins\Android\

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

https://forum.unity.com/threads/gradle-build-error-gradle-version-2-10-is-required-current-version-is-4-0-1.499520/