Gradle Error: Problem with Gradle build

Hi guys how are you?

I’m having a build problem at Unity with gradle, I’ve been trying to solve this problem for some time, but I have not been able to do anything at the moment. I would appreciate some help, really!

Problem occurs when I try to build my apk with gradle, that’s the problem


And this is the log

CommandInvokationFailure: Gradle build failed.
C:\Program Files\Java\jdk1.8.0_162\bin\java.exe -classpath "C:\Program Files\Unity\Hub\Editor\2018.2.0b10\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\gradle\lib\gradle-launcher-4.2.1.jar" org.gradle.launcher.GradleMain "-Dorg.gradle.jvmargs=-Xmx2048m" "assembleRelease"

stderr[

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'gradleOut'.
> Could not resolve all files for configuration ':classpath'.
   > Could not find gradle.jar (com.android.tools.build:gradle:3.0.1).
     Searched in the following locations:
         https://jcenter.bintray.com/com/android/tools/build/gradle/3.0.1/gradle-3.0.1.jar
   > Could not find layoutlib-api.jar (com.android.tools.layoutlib:layoutlib-api:26.0.1).
     Searched in the following locations:
         https://jcenter.bintray.com/com/android/tools/layoutlib/layoutlib-api/26.0.1/layoutlib-api-26.0.1.jar
   > Could not find apksig.jar (com.android.tools.build:apksig:3.0.1).
     Searched in the following locations:
         https://jcenter.bintray.com/com/android/tools/build/apksig/3.0.1/apksig-3.0.1.jar

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

* Get more help at https://help.gradle.org

BUILD FAILED in 54s
]
stdout[
Starting a Gradle Daemon, 1 incompatible and 1 stopped Daemons could not be reused, use --status for details
]
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 (UnityEditor.Android.AndroidJavaTools javaTools, System.String workingdir, System.String task, System.Action`1 progress)
Rethrow as GradleInvokationException: Gradle build failed
UnityEditor.Android.GradleWrapper.Run (UnityEditor.Android.AndroidJavaTools javaTools, 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)

Already tried

  • Update the JDK
  • Downgrade JDK
  • Use another version of Unity
  • Reinstall the JDK and SDK
  • Only let the SDK 26/27 or 28 installed
  • Update Android Studio
  • Reinstall Unity
  • Install all SDK tools using the Android Studio SDK Manager

None of these things helped me…

I’m using

  • Unity 2018.2.0b10
  • Android Studio 3.1.3
  • JDK 1.8.0_172
  • Android SDK 27
  • A completely clean project on Unity
3 Likes

What Unity version are you using?
Also, are you using a custom gradle template file (for your main app or for any other libraries you include) ? please share those files as well.

Hi!

The Unity version is 2018.2.0b10, and I’m not using any custom gradle files. The project also does not have any type of plugin…

Can you try creating a new empty project and build that for Android. See if you get the same results ?

I created a new project and Unity made the same mistake!

if you are using a custom Gradle file, make sure that it includes:

repositories {
jcenter()
google()
}

1 Like

Did you ever solve your problem?

did you solve it?

Unfortunately I was unable to solve the problem, so I just configured my Unity (at the time) to use the Internal compiler instead of Gradle …

After having this problem I spent some time without using Unity, but when I returned, the problem just didn’t happen anymore. I heard that this has to do with the versioning of Gradle, but as the problem no longer occurred, I was unable to identify it :confused:

thanks worked for me after downgrading to unity 2018 and using internal compiler .

I clicked Development Build on, in the build settings and it solved. I didnt get any such errors.

1 Like

In my case it was caused by a non-ASCII character in project path… Fixed the path and prblem was gone

2 Likes

i use Unity 2020.3.9
The problem is still there and I can’t solve it yet
If any of you have the problem, please help me

I’m having the same problem on Unity 2020.3.15f2… been a pain to install a lot of things to compile in aab and this is almost the last step, and can’t find a way to work it out :frowning:

same problem 2019.4.29f stucked on 2 days…

FIX: move project folder from downloads, because in my user name was non latin letters

1 Like

OK, how are you?

I know it isn’t much of a solution, but a reboot fixed this for me. I did not see a gradle process in Mac OS Activity Monitor, but likely something like that could be killed instead of rebooting, until there is a Unity Editor fix.

A reboot indeed got it back to work correctly. Cheers

1 Like

could you fix it?

What worked for me was to update Unity to the latest LTS version. I also noticed when I built first that Avast blocked some file execution which caused the build to fail. I manually added an exception. You might want to check that your anti virus didn’t block any executable.
Also I noticed that gradle failed to build when not connected to network as it needs to pull some data sometimes.
Hope it helps

For me the solution was enabling USE R8 in my unity 2020.3 inside publishing settings Minify

1 Like