You press Build, wait several minutes, and Unity shows a red “Gradle build failed”. That message only tells you that something went wrong. The actual cause is buried further down in Gradle’s output, and it’s usually one of a dozen well-known problems: missing or mismatched SDK tools, a plugin conflict, a manifest merge error, a signing issue or an API level Google Play won’t accept. This guide shows how to find the real error in seconds and gives the fix for each common one in Unity 6.
Step 1: Find the Real Error
Unity’s summary is almost always CommandInvokationFailure: Gradle build failed. followed by a long wall of text. Don’t read it from the top. Instead:
- Click the error in the Console so the full message appears in the lower panel. Right-click the Console tab and choose Open Editor Log if you want the complete output in a text editor.
- Search for
What went wrong:. Gradle puts the actual cause directly below that line. - If there are several errors, the first one is the cause. The rest are usually knock-on failures.
Also check the Console for errors that appear before the Gradle step. A C# compile error or a failed IL2CPP step stops the build too, and the Gradle message is just the last thing printed. If you see error CS... lines, fix those first; our Unity compiler errors guide covers the common ones.
Step 2: Check Your Android Setup
A large share of Gradle failures come from the toolchain rather than your project. Unity 6 is tested against specific versions of the Java JDK, Android SDK, NDK and Gradle, and it’s easiest to use the ones Unity installs.
Install the modules through Unity Hub
In Unity Hub, open Installs, click the gear icon on your Unity 6 version, choose Add modules, and make sure all three are ticked:
- Android Build Support
- Android SDK & NDK Tools
- OpenJDK
Unity 6 uses JDK 17. Recent Unity 6.0 releases pair with NDK r27c (6000.0.38f1 and later; earlier 6.0 releases used r23b) and ship SDK build tools that match current Google Play requirements. Updating Unity to the latest 6.x patch release updates this toolchain too, which fixes many problems on its own.
Point Unity at the right tools
Open Edit > Preferences > External Tools (Unity > Settings on macOS) and scroll to the Android section. For the JDK, Android SDK, NDK and Gradle, tick Installed with Unity (recommended). If you previously pointed any of these to your own installation, such as an Android Studio SDK or a system-wide Java, that mismatch is a prime suspect. Switch back to the Unity-installed versions before debugging anything else.
Test with an empty project
Create a new empty Unity 6 project, switch the platform to Android in File > Build Profiles, and build. If an empty project fails, the problem is your setup (modules, tools, disk space, antivirus). If it succeeds, the problem is in your project: plugins, manifests, templates or settings.
Common Gradle Errors and Fixes
Duplicate class … found in modules
Two plugins include the same Android library. For example, two SDKs each bundle their own copy of a Google or AndroidX library. The error names the class and both modules containing it. Fixes:
- Search
Assets/Plugins/Androidfor duplicate.aaror.jarfiles with the same library in different versions, and delete the older one. - If your plugins use the External Dependency Manager (common with Google and ad SDKs), use its Android Resolver to Delete Resolved Libraries and then Force Resolve, so it downloads one consistent set.
- Update the plugins. SDK vendors fix these conflicts in newer versions.
Manifest merger failed
Every plugin can include its own AndroidManifest.xml, and Gradle merges them. When two define the same attribute with different values (a common case is android:allowBackup or the application’s theme), the merge fails and Gradle suggests adding tools:replace. To fix it:
- In Project Settings > Player > Android > Publishing Settings, tick Custom Main Manifest. Unity creates
Assets/Plugins/Android/AndroidManifest.xml. - Make sure the root
<manifest>tag declaresxmlns:tools="http://schemas.android.com/tools". - Add
tools:replace="android:allowBackup"(using the attribute named in the error) to the<application>tag, and set the value you want.
A related error occurs when a plugin’s manifest references a resource that doesn’t exist, such as an icon or string. The message names the missing resource; update or fix that plugin.
uses-sdk:minSdkVersion … cannot be smaller than version … declared in library
A library needs a higher minimum Android version than your project allows. Raise Minimum API Level in Player > Android > Other Settings to at least the version in the message. Also remove any minSdkVersion set directly in a custom manifest; Unity manages it from Player Settings, and a hard-coded value there causes conflicts of its own.
Android SDK or JDK not found, or “licenses not accepted”
Unity can’t find a tool it needs, or the SDK is missing a platform or build-tools version. Go back to Step 2: reinstall the Hub modules and tick every “Installed with Unity” box. If you use your own SDK, open its SDK Manager, install the platform and build-tools version named in the error, and accept the licences.
java.lang.OutOfMemoryError: Java heap space
Gradle ran out of memory, common with large projects and many plugins. Tick Custom Gradle Properties Template in Publishing Settings and, in the generated gradleTemplate.properties, raise the heap in the org.gradle.jvmargs line, for example to -Xmx4096M. Close other heavy applications while building. If your machine has 8 GB of RAM, Android builds are where you’ll feel it most.
Could not resolve all files for configuration
Gradle couldn’t download a dependency. Check your internet connection, VPN, proxy or company firewall; the first Android build downloads many packages. If the message names a specific library version, the plugin may reference a version or repository that no longer exists; update the plugin. Repositories are listed in the Custom Main Gradle Template and Custom Settings Gradle Template if you’ve enabled them.
Keystore was tampered with, or password was incorrect
The release signing step failed, almost always because the keystore or key alias password in Publishing Settings > Keystore Manager is wrong. Unity doesn’t save these passwords between sessions, so re-enter both after reopening the project. Keep your release keystore and its passwords backed up somewhere safe: if you lose them, you can’t update your app on Google Play without going through Play App Signing key recovery.
Package name conflicts or invalid package name
Your Package Name in Player Settings must be a valid Java-style identifier (for example com.yourstudio.yourgame: letters, digits and underscores, no segment starting with a digit, no hyphens). A conflict error means two libraries declare the same package or namespace; one of them needs updating or removing.
IL2CPP errors before Gradle runs
If the log shows IL2CPP or clang errors, the native build failed before Gradle. The usual causes are the wrong NDK version (fix it in External Tools), antivirus software locking files in the Library folder, or a project path that’s very long or contains unusual characters. Move the project to a short path such as C:\Dev\MyGame and try again.
⏱️ Android builds taking forever?
IL2CPP and Gradle are some of the most CPU and memory-hungry things you’ll do in Unity. A laptop with 16 GB of RAM, a fast SSD and a modern CPU can cut build times dramatically. See our budget picks, or take the 60-second quiz to get a recommendation.
Best budget laptops for Unity → · Laptop recommendation quiz →
Google Play Requirements (API 36, 64-bit, AAB)
A build that succeeds can still be rejected when you upload it. Set these before your first upload:
- Target API level. Since August 31, 2026, new apps and app updates on Google Play must target Android 16 (API level 36). Developers can request an extension until November 1, 2026. In Player > Android > Other Settings, set Target API Level to Automatic (highest installed) and make sure the installed SDK platform is API 36. On an older Unity 6 patch, update Unity if it doesn’t offer API 36.
- 64-bit. Set Scripting Backend to IL2CPP and tick ARM64 under Target Architectures. Mono only builds 32-bit ARMv7, which Google Play doesn’t accept on its own.
- App Bundle. Tick Build App Bundle (Google Play) in the build profile to produce an
.aabinstead of an.apk. Google Play requires AAB for new apps. - Version code. Increase Bundle Version Code for every upload, or Play Console rejects it as a duplicate.
Our Unity project settings checklist has these alongside the other settings to review before release.
The Clean Rebuild
When settings look right but the build keeps failing with stale errors, clear Unity’s cached Android build files:
- Close Unity.
- Delete the
Library/Bee/Androidfolder in your project. Unity generates the Gradle project there and rebuilds it from scratch. Deleting the wholeLibraryfolder also works but forces a full reimport, which takes longer. - If you use the External Dependency Manager, run Force Resolve again after reopening.
- Build again.
If you’re unsure what you changed since the last working build, version control makes this easy: compare ProjectSettings and Assets/Plugins/Android against the last good commit. Our Git setup guide for Unity walks through the setup.
Faster Test Builds and On-Device Debugging
Every failed build costs minutes, so it pays to make test builds quicker and to see what happens on the device:
- Use a faster configuration while testing. In Player Settings, set IL2CPP Code Generation to Faster (smaller) builds for day-to-day testing, and switch back to faster runtime for release. Only enable ARM64 for test builds unless you need to test on an old 32-bit device.
- Build And Run over USB. Enable Developer options and USB debugging on your phone, connect it, select it as the Run Device in the build profile, and use Build And Run. Unity installs and launches the app for you.
- Read the device log. Install the Android Logcat package from the Package Manager and open it from Window > Analysis > Android Logcat. It shows your
Debug.Logoutput and native crashes from the phone. If the build succeeds but the app closes immediately on launch, the reason is almost always in this log: filter by your package name and look for the first error or exception. - Development Build. Tick Development Build (and Script Debugging if you want to attach your IDE) to get readable stack traces. Turn it off for store builds.
Export to Android Studio for Hard Cases
For complex conflicts, Unity’s own documentation recommends exporting the project. In the build profile, tick Export Project and build. Unity writes a complete Gradle project instead of an APK or AAB. Open the folder in Android Studio, let it sync, and build there. Android Studio shows each error with a link to the exact file and line, and its Merged Manifest tab shows which plugin contributed each manifest entry, which is invaluable for merge conflicts. Once you’ve found the fix, apply it in Unity (in a custom template or manifest) so it’s kept in future builds; don’t hand-edit the exported project and rely on that.
FAQ
How do I see why the Gradle build failed?
Click the error in the Console or open the Editor log, then search for “What went wrong:”. The line after it is the real cause. Fix the first error listed.
Which JDK does Unity 6 use for Android?
JDK 17, installed through the OpenJDK module in Unity Hub. Using the Unity-installed JDK avoids most version mismatches.
What target API does Google Play require in 2026?
Since August 31, 2026, new apps and updates must target API level 36 (Android 16), with an optional extension to November 1, 2026.
How do I fix “Duplicate class found in modules”?
Remove duplicate .aar or .jar libraries from Assets/Plugins/Android, or use the External Dependency Manager to delete resolved libraries and force resolve.
How do I fix “Manifest merger failed”?
Enable a Custom Main Manifest in Publishing Settings and add tools:replace for the conflicting attribute to the application tag.
Is it safe to delete the Library folder?
Yes. Unity regenerates it, though a full reimport can take a while on large projects. Deleting only Library/Bee/Android is faster for Android build problems.
Reader questions
Asked by readers of this article and answered by AI. Behavior can differ between Unity versions, so test in yours.




Leave a Reply