How to Fix “Gradle Build Failed” Errors in Android Studio

You press Run, wait a few seconds, and the console fills with red text ending in “Gradle build failed.” It is one of the most common and most frustrating problems in Android development. It happens in Android Studio, in Unity when you export a game, and in React Native or Expo when you create a build. The good news: the message itself says almost nothing, but the cause is nearly always a mismatch between a few well-known pieces. This guide explains what is going on and walks through the fixes for all three setups.

What “Gradle build failed” really means

Gradle is the build tool behind every Android app. It takes your code, resources and libraries, and packages them into an APK or AAB file that can be installed on a phone. To do that it needs several things to line up: the Android SDK, the right Gradle version, the right Android Gradle plugin version, and dependencies it is able to download and understand.

When one of those is missing, outdated or incompatible, Gradle stops and reports a failure. That is why the same error shows up so often on projects you download from websites or old tutorials: they were built with versions that are no longer available or no longer supported.

Diagram: code goes through Gradle to become an app, and the build fails if something is wrong
When one ingredient is wrong, Gradle stops the build.

Step zero: find the real error

“Gradle build failed” is only the headline. The actual reason is written a little higher in the output. In Android Studio, open the Build tab and scroll up until you see the line under What went wrong, plus the file and line number it points to. Copy that exact message, because it tells you which fix below applies.

Example build error with the key line highlighted
The “What went wrong” line is the real cause.

Careful with silent errors. Some tools, such as Expo builds, may show only a vague “unknown error” and leave you to work out the cause. Do not panic. The cause is usually one of the version problems below, and the Expo section shows exactly how to track it down.

Quick diagnosis table

What you see Likely cause Go to
Plugin was not found, or a version “was not found in the following sources” Old project using a plugin or Gradle version that is outdated or removed Fix 1
A downloaded project won’t run, or SDK errors Wrong SDK location, missing SDK platform or tools Fix 2
Unity export stops near the end (around 95%) and a console window appears JDK/SDK/NDK/Gradle not installed with Unity, API levels or dependencies not resolved Fix 3
Expo build ends with an unknown error Packages not supported by the newer Gradle version Fix 4

Fix 1: Update the plugin and Gradle versions

A typical message looks like this: the plugin is not found in the plugin repositories, and the build file points to a specific line (for example line 3) with a version such as 3.2.0 that “was not found in the following sources.” This usually happens when you open an old project and the plugin version it asks for has been removed or is out of date.

Step 1: Update the Gradle wrapper

Open gradle/wrapper/gradle-wrapper.properties and check which Gradle version the wrapper uses. Update it to a newer version that matches your plugin:

gradle/wrapper/gradle-wrapper.properties
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip

Step 2: Update the plugin version

Your plugin version is declared in the project-level build file. Change it to a version available in the repository:

plugins {
    id 'com.android.application' version '8.0.1' apply false
    id 'com.android.library' version '8.0.1' apply false
}

Older projects declare it like this instead, and the same rule applies:

classpath 'com.android.tools.build:gradle:8.0.1'

Step 3 (easier): Use Project Structure

You don’t have to edit files by hand. Go to File > Project Structure > Project and choose a version that exists in the repository for both the Android Gradle plugin and Gradle. In the walkthrough, both were set to the 8.0 family (plugin 8.0.1 and Gradle 8.0). Click OK, let the sync start again, and the build completes without errors.

Android Studio Project Structure with plugin and Gradle version fields
File > Project Structure: update both versions.

Keep versions in step. The plugin, Gradle and the JDK have to be compatible with each other. For example, Android Gradle plugin 8 needs JDK 17. If you raise one version and the build still fails, check the official compatibility table for the others instead of changing them one at a time.

Plugin, Gradle, JDK and SDK must be compatible
Keep these four in step.

Fix 2: Check your Android SDK setup

If you run projects downloaded from websites or other platforms, a proper SDK setup avoids many issues. Check these three places in Android Studio:

  1. SDK location. Go to File > Project Structure and confirm the Android SDK location points to a real, proper directory. In the same dialog you can also see the Gradle version the project uses.
  2. SDK Platforms. In Settings > Languages & Frameworks > Android SDK, open the SDK Platforms tab. Make sure the platform your project needs is installed (the example used Android 11.0 “R”, API level 30). Click Show Package Details to see exactly what is installed.
  3. SDK Tools. Open the SDK Tools tab and install the tools needed to run Android projects. If they are missing, you will get an error.

There is also a third tab, SDK Update Sites, which lists the sites Android Studio uses to check for SDK updates. Compare it with a working setup if updates are not being found. To see which Android Studio version you have, check Appearance & Behavior > System Settings > Updates.

Fix 3: Unity export fails at around 95%

In Unity, the classic symptom is the progress bar reaching about 95%, then a console window opens and the export ends with “Gradle build failed.” Work through these checks in order.

Check 1: External Tools

Go to Edit > Preferences > External Tools. Under the Android section, the JDK, Android SDK and NDK should be installed with Unity, and Gradle too. Use the “installed with Unity (recommended)” options and make sure they are ticked. If they are missing, install a recommended (LTS) Unity version through Unity Hub, and enable Android Build Support with OpenJDK and Android SDK & NDK Tools.

Check 2: Build Settings

  • Switch the platform to Android.
  • Tick Development Build only while you are testing. Untick it for a release build.
  • Keep only the scene(s) you actually need in the build. Remove extra scenes.
  • The video also advises enabling Google’s app bundle option only if you need it and keeping it disabled otherwise.

Check 3: Player Settings, Other Settings

This is the most important place. Open Player Settings and go to the last section, Other Settings.

  • Set a proper package name (replace the default) and a version. A bundle version code is required.
  • Minimum API Level: a wrong value can cause the failure. If the build fails, raise it step by step. The example fixed it by moving up to Android 7.1.
  • Target API Level: choose the highest installed (for example API 34). A pop-up may appear asking you to resolve dependencies, which is covered below.
  • Scripting Backend: IL2CPP instead of Mono.
  • API Compatibility Level: .NET Standard 2.1.
  • C++ Compiler Configuration: Release.
  • Target Architectures: tick both ARMv7 and ARM64. Because you use IL2CPP, leaving both unticked can cause Gradle problems.
Unity player settings that help avoid Gradle failures
Key Unity settings to double-check.

Check 4: Resolve dependencies

Go to Assets > External Dependency Manager > Android Resolver and run Resolve. If the build still fails, save your project and duplicate it first as a backup, then run Force Resolve. A dialog appears and downloads dependencies. That is normal and expected. Then build again and test the result on a phone.

Force Resolve works by changing some files. Also check the Android Resolver settings and make sure the option to patch the main Gradle template (mainTemplate.gradle) is enabled, so the manifest is patched and the newer update is applied on top.

Why duplicate first? Force Resolve can change project files. A copy lets you roll back if something unrelated stops working.

Fix 4: Expo build fails with an unknown error

When you run an Android build for a profile such as development or production (for example eas build --platform android --profile development), the process runs for a while and then ends with a message that Gradle failed with an unknown error. It doesn’t say which error or how to fix it.

In this case the cause is that your project uses packages that worked with earlier Gradle versions but are no longer supported in the newer one (Gradle 9.0 in the example). The message hints that some features used in your build are incompatible with it.

How to fix it

  1. Run the Expo check to list packages that don’t have the correct version for your SDK:
    npx expo install --check
  2. Update the packages it lists.
  3. Open package.json and look for duplicated or deprecated packages. Uninstall each one and install a supported replacement, or build the feature yourself. A real example: expo-av was replaced by the separate expo-video and expo-audio packages. If the old package stays in your project, the build won’t succeed.
  4. Run the build again. Once the unsupported packages are removed, the build should succeed.
Replacing an unsupported Expo package so the build succeeds
Swap the unsupported package, then rebuild.

Don’t rely on generic internet advice. A common suggestion is to run Gradle in watch mode to reveal the error. In this case it doesn’t show it. The reliable approach is the one above: find unsupported or duplicated packages and replace them.

Quick recap by setup

Find your setup below and follow the three steps. Rebuild after each fix so you know which change solved it.

Setup Step 1 Step 2 Step 3
Android Studio Read the “What went wrong” line Update the plugin and Gradle together Check SDK location, platforms and tools
Unity Fix External Tools (JDK, SDK, NDK, Gradle) Set API levels, IL2CPP and both architectures Resolve dependencies (Force Resolve on a copy)
Expo / EAS Run npx expo install –check Remove unsupported or duplicated packages Install replacements and rebuild

Common mistakes and gotchas

Mistake Why it causes trouble
Only reading the “Gradle build failed” headline The real cause is higher up under “What went wrong”
Updating only the plugin or only Gradle They must be compatible with each other and with your JDK
Running an old downloaded project without checking versions Its plugin or Gradle version may no longer exist
Missing SDK platform or SDK tools Gradle can’t build against what isn’t installed
In Unity, leaving ARMv7 and ARM64 unticked with IL2CPP Can lead to Gradle build errors
Keeping unnecessary scenes and a Development Build in a release Adds avoidable issues and unneeded content
Running Force Resolve with no backup It modifies files and is hard to undo
Keeping unsupported or duplicated Expo packages The build won’t succeed with the newer Gradle version
Changing many settings at once You won’t know which change fixed (or broke) the build

Frequently asked questions

What does “Gradle build failed” mean?

It means Gradle could not turn your project into an app. The reason is shown elsewhere in the output, and it is usually a missing, outdated or incompatible SDK, Gradle version, plugin or dependency.

Why does a downloaded project fail to build?

Most likely it was made with versions you don’t have, or that no longer exist. Check the plugin and Gradle versions, and make sure your SDK setup is complete.

Where do I find the Gradle version in Android Studio?

Go to File > Project Structure > Project. You can see and change the Android Gradle plugin version and the Gradle version there.

Why does my Unity export stop at 95%?

That is usually the Gradle step failing. Check External Tools, the API levels in Player Settings, the scripting backend and architectures, and resolve dependencies.

Is it safe to use Force Resolve in Unity?

It is a standard fix, but it changes files. Always duplicate your project first and test the build on a phone afterwards.

Do I need to update Gradle and the plugin together?

Yes, treat them as a pair, along with the JDK. Check the official compatibility information before changing versions.

My Expo build only says “unknown error”. What now?

Run npx expo install --check, review package.json for unsupported or duplicated packages, replace them with supported ones, and build again.

Should I use a Development Build for release?

No. Use it only while testing and untick it when you are ready to release.

Conclusion

“Gradle build failed” looks scary, but it is almost always a version problem. Read the real error first, then work in order: update the plugin and Gradle together, make sure your Android SDK and tools are installed, and in Unity or Expo, correct the settings and packages that don’t fit your Gradle version.

Change one thing at a time, rebuild after each change and test the final build on a real phone. If a fix doesn’t work, the exact “What went wrong” message is your best clue for what to try next.

Leave a Reply

Your email address will not be published. Required fields are marked *