Why Gradle Errors Are So Frustrating
If you've spent any time developing Android apps, you've almost certainly been stopped dead by a cryptic Gradle error. The build system is powerful, but its error messages can feel deliberately unhelpful. This guide breaks down the most common build failures, explains why they happen, and gives you clear steps to resolve them.
1. Duplicate Class Error
One of the most common errors introduced after adding a new dependency:
Duplicate class kotlin.collections.jdk8 found in modules...
Why it happens
Two or more dependencies pull in different versions of the same class, usually when mixing Kotlin standard library versions or using an old kotlin-stdlib-jdk7 dependency alongside a newer Kotlin plugin that bundles the same classes.
How to fix it
- Open your app-level build.gradle and add an explicit dependency exclusion:
dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib") {
exclude group: "org.jetbrains.kotlin", module: "kotlin-stdlib-jdk7"
exclude group: "org.jetbrains.kotlin", module: "kotlin-stdlib-jdk8"
}
}
- Alternatively, set a forced resolution strategy in your project-level Gradle file.
- Upgrade your Kotlin Gradle plugin to the latest stable version — newer versions handle this automatically.
2. Manifest Merger Failed
Manifest merger failed: Attribute application@label value=(@string/app_name)
from AndroidManifest.xml conflicts with...
Why it happens
When a library you've added has its own AndroidManifest.xml, the build system attempts to merge it with yours. Conflicts arise when both manifests declare the same attribute with different values.
How to fix it
Use the tools:replace attribute in your manifest to tell the merger which value should win:
<application
android:label="@string/app_name"
tools:replace="android:label">
3. Execution Failed for Task ':app:dexBuilderDebug'
Why it happens
Your app has exceeded the 64K method reference limit — a DEX file limitation. This typically surfaces after adding several third-party libraries.
How to fix it
- Enable multidex support in your
build.gradle:
android {
defaultConfig {
multiDexEnabled true
}
}
dependencies {
implementation 'androidx.multidex:multidex:2.0.1'
}
- Have your
Applicationclass extendMultiDexApplication. - Consider auditing your dependencies — you may be pulling in entire libraries when you only need a small subset.
4. Could Not Resolve Dependency
Could not resolve com.example:library:1.0.0
Why it happens
The specified library version doesn't exist in the repositories configured, the repository itself is unreachable, or your network is blocking the download.
How to fix it
- Verify the exact version number on mvnrepository.com or the library's GitHub releases.
- Ensure
mavenCentral()orgoogle()is listed in your settings.gradle (not just project-level Gradle). - Try running with
--refresh-dependenciesto force a fresh fetch. - Check if your corporate network or proxy is blocking Maven repositories.
5. Configuration Cache Problems
Gradle's configuration cache is a performance feature that can cause issues when plugins aren't fully compatible with it.
How to fix it
Temporarily disable it by adding this to your gradle.properties:
org.gradle.configuration-cache=false
Then check whether the plugin responsible has a newer version with configuration cache support.
Quick Diagnostic Checklist
- Run
./gradlew build --stacktracefor the full error chain. - Use
./gradlew dependenciesto visualize the dependency tree. - Invalidate caches in Android Studio: File → Invalidate Caches / Restart.
- Keep Gradle, the Android Gradle Plugin, and Kotlin plugin versions in sync.
Final Thoughts
Gradle errors are rarely as catastrophic as they first appear. The key is learning to read the error output from the bottom up — the root cause is almost always buried below the cascade of failures. Bookmark the official Android build documentation and use --stacktrace liberally.