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.
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
- Open the Gradle stack trace under the build log.
- Pin the Android Gradle Plugin, Gradle, and JDK to a compatible set for your editor version.
- 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.
# Use a GameCI Android editor image so bundled Gradle/JDK are used
customImage: unityci/editor:ubuntu-2022.3.21f1-android-3How 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.