Gradle & Code Quality

Duplicate Class Build Errors: Find the Two Owners of the Same Class

A duplicate-class error means two packaged inputs define the same class. This is different from requesting two versions of the same module: Gradle can often select one module version, but it cannot safely merge two independent owners of identical class names.

By Updated 2 min read

Capture both owners

Copy the class name and both artifact paths from the error. Typical causes include a local JAR plus its Maven equivalent, a bundled SDK plus a standalone copy, or old and new library families included together.

Use the Android dependency guidance to trace how those inputs reach the module.

Inspect the dependency paths

BASH · REFERENCE EXAMPLE
./gradlew :app:dependencies --configuration releaseRuntimeClasspath
./gradlew :app:dependencyInsight \
  --dependency conflicting-module \
  --configuration releaseRuntimeClasspath

The second command uses a placeholder module name. The Gradle report guide explains how to read selection and parent paths.

Remove the redundant ownership

Duplicate source Typical resolution
libs/ JAR and repository dependency Keep one supported distribution
SDK embeds a library also declared separately Follow the SDK's integration guidance
Legacy and replacement artifacts coexist Complete the documented migration
Two unrelated publishers bundle the same package Request compatible packaging or replace one

A version force cannot solve every case because the duplicate may come from different coordinates.

Do not hide code duplication with resource rules

Packaging exclusions intended for metadata files are not a general solution for duplicate executable classes. Removing a class from an archive manually also creates an unsupported artifact with unclear compatibility.

A narrow transitive exclusion can be valid, but verify that the remaining copy satisfies all consumers and that the publisher supports the combination.

Recheck every relevant variant

Build the same variant that failed, then check other flavors using different SDK sets. APKLint's dependency review can help locate suspicious overlaps, but the complete error and resolved build inputs are necessary to identify the two actual owners. Keep those artifacts and paths in the fix record so the same duplicate does not return during a later SDK update.

Sources and further reading

  1. Android Developers: Add build dependencies
  2. Gradle: Viewing and debugging dependencies

Reference review: 22 September 2026. Examples illustrate the workflow; check your installed versions, release artifact and account-specific Console requirements before applying them. This guide is not a claim that APKLint executed your project or verified your private account.

APKLint

Android inspection tools and practical release guides. About APKLint · Report a correction