Skip to content
Latchkey

Unity "Gradle build failed" for Android in CI

After Unity exports the Android project, Gradle assembles the APK or AAB. A "Gradle build failed" message means the failure is in the Gradle step: a plugin conflict, a missing repository, or a Gradle/JDK version mismatch.

What this error means

The build reaches "CommandInvokationFailure: Gradle build failed" with a Gradle stack trace, after the Unity export but before the package is produced.

unity
CommandInvokationFailure: Gradle build failed.
> Could not resolve all dependencies for configuration ':classpath'.
> Could not find com.android.tools.build:gradle:...

Common causes

A plugin or dependency cannot be resolved

A custom mainTemplate.gradle, an Android plugin, or a repository that is unreachable makes Gradle fail to resolve the dependency graph.

A Gradle or JDK version mismatch

The Gradle version the editor uses does not match the Android Gradle Plugin or the JDK, so the assemble task fails.

How to fix it

Read the Gradle failure and align versions

  1. Open the Gradle stack trace under the build log.
  2. Pin the Android Gradle Plugin, Gradle, and JDK to a compatible set for your editor version.
  3. Ensure all referenced Maven repositories are reachable from CI.

Use the editor-bundled Gradle and JDK

Prefer the Gradle and JDK that ship with the Android editor module rather than a host install that may be a different version.

.github/workflows/ci.yml
# Use a GameCI Android editor image so bundled Gradle/JDK are used
customImage: unityci/editor:ubuntu-2022.3.21f1-android-3

How to prevent it

  • Keep AGP, Gradle, and JDK versions compatible with the editor.
  • Use the editor-bundled Gradle/JDK for reproducibility.
  • Confirm custom Gradle templates resolve all repositories.

Frequently asked questions

What causes ""Gradle build failed" (Android)"?
A custom mainTemplate.gradle, an Android plugin, or a repository that is unreachable makes Gradle fail to resolve the dependency graph.
How do I fix "Gradle build failed" (Android)?
Read the Gradle failure and align versions

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card