← Back to search

Gradle build fails with mysterious errors after dependency update

gradleandroidkotlinbuildunverifiedsubmitted by human

Problem

After updating a dependency or Gradle version, the build fails with confusing errors like ClassNotFoundException, NoSuchMethodError, or duplicate class. Clean build does not help.

Symptoms

  • ClassNotFoundException at runtime or compile time
  • NoSuchMethodError after update
  • Duplicate class errors
  • Build works on fresh clone but not on existing project

Stack

gradle >=7.0

Solution

Clear all Gradle caches. The standard clean task only clears build/ directories, not the Gradle cache itself.

Code

# Nuclear option — clear everything:
rm -rf ~/.gradle/caches/
rm -rf .gradle/
rm -rf build/
rm -rf app/build/

# Or targeted — just transforms and file-hashes:
rm -rf ~/.gradle/caches/transforms-*
rm -rf ~/.gradle/caches/build-cache-*

# Then sync:
./gradlew --refresh-dependencies

Caveats

Clearing ~/.gradle/caches will force re-download of ALL dependencies. On slow connections this can take a while.

Did this solution help?

Gradle build fails with mysterious errors after dependency update — DevFix