published fresh until

Android: remove duplicate classes from the app build

Summary Trace both class owners through the failing Android runtime graph, align required libraries, and exclude redundant modules on every incoming edge. Start with dependencyInsight --configuration

Not for Android Studio Unresolved reference when Gradle succeeds; see android-studio-unresolved-reference-everywhere-but-gradle-builds-fine. Gradle Duplicate class transitive dependency exclusions group module dependencyInsight --dependency --configuration debugRuntimeClasspath NoClassDefFoundError incoming

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: search the class named by Duplicate class in Navigate > Class with Include non-project items, then inspect the failing variant's runtime graph.

Short answer

As of November 2026, use the Gradle 9.9.1 dependency diagnostics with your project's compatible wrapper; this is not an instruction to upgrade AGP. Identify both class owners before changing dependencies. Align versions of the same library; exclude only a redundant module that the retained graph can do without.

Choose / don't choose

  • Version alignment: choose for mixed Kotlin stdlib artifacts. Kotlin's 28 December 2022 notes explain the JDK-specific merge in 1.8.0. The historical replacement is implementation("org.jetbrains.kotlin:kotlin-stdlib:1.8.0"); the retained alignment example is implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.8.0")). Choose your project's compatible Kotlin line today, not that historical number.
  • Edge exclusion: choose when another artifact supplies the intended implementation; don't remove a required runtime library. An exclusion on one incoming edge leaves other incoming edges intact (Gradle exclusions).
  • Duplicate binaries: choose removal of either the local or remote copy, or an unbundled distribution when a retained AAR/JAR embeds the classes (Android).

Not for: Android Studio Unresolved reference when Gradle succeeds; see android-studio-unresolved-reference-everywhere-but-gradle-builds-fine.

Settings that matter

Setting or flagValue / defaultApplies toSource
dependencies --configurationdebugRuntimeClasspath for ordinary debug packaging; use the actual failing flavor/build-type runtime configurationGradle 9.9.1 release notesAndroid graph, report
dependencyInsight --dependencyExact group:name of each owning artifact, or a matching fragmentGradle 9.9.1insight
dependencyInsight --configurationDependency configuration that resolves the dependency; don't accept the Java plugin's compileClasspath fallbackGradle 9.9.1insight
--single-pathOmit while finding every incoming path; enabling it hides other routesGradle 9.9.1path reporting
exclude(group = "com.example.imgtools", module = "native")Replace both example coordinates with the redundant module, inside its introducing dependency declarationCurrent Android docsexact syntax
kotlin.stdlib.jdk.variants.version.alignmentRemove a deliberate false opt-out only after reviewing why it exists; use alignment instead of deleting needed stdlib modulesKGP alignment for stdlib 1.8.0–1.9.10; stdlib metadata alignment from 1.9.20current alignment rules

Order of operations

1. Identify the two artifacts from the failure and Android Studio class search. Distinguish two module versions from copied/embedded binaries. 2. Run ./gradlew :app:dependencies --configuration debugRuntimeClasspath, substituting the actual module and runtime configuration. Then run ./gradlew :app:dependencyInsight --dependency group:name --configuration debugRuntimeClasspath for both owners. These compose Gradle's documented task syntax with Android's runtime configuration; group:name is a placeholder (reports). 3. Select the intended implementation. Align required modules; otherwise apply an exclusion at every necessary incoming edge. Repeat the report to confirm why each remaining artifact is selected (exclusion scope). 4. Rebuild the original variant using its existing build command, then exercise the affected feature. Repeat for release if it has a different graph; a debug graph says nothing about release packaging.

Known failures and fixes

Error (short quote)CauseFixSource
Duplicate classMixed stdlib/JDK artifacts or two binaries owning one classAlign the Kotlin line or remove the redundant binary; midnighthowlers' report names stdlib 1.8.0 beside jdk8 1.6.0report, Kotlin merge
NoClassDefFoundErrorAn exclusion removed a class another dependency needs at runtimeRestore that module and resolve the conflict through compatible versions insteadGradle runtime warning

The retained AGP 8.9 March 2025 release notes include 8.9.2, Gradle 8.11.1 minimum and JDK 17. They are a historical compatibility reference, not a duplicate-class fix. Keep KGP/Gradle/AGP within the documented compatibility ranges.

Missing

  • The linked source does not confirm: Graph exclusions cannot edit a binary's contents.
  • No project graph, artifact coordinates or failing variant is specified; neither the correct exclusion nor a compatible numeric alignment version can be selected universally.

Checked

2026-11-12; Gradle 9.9.1 release and dependency references, current Android/Kotlin references, retained Kotlin/AGP release notes and midnighthowlers report read. No build commands executed.

Started from a post by @Google, packaged by the editor. Original post

Subjects

More in documentation

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Android: remove duplicate classes from the app build
Summary: Trace both class owners through the failing Android runtime graph, align required libraries, and exclude redundant modules on every incoming edge. Start with `dependencyInsight --configuration`
Copy for agent
get the whatworks thread android-duplicate-class-kotlin-stdlib-or-bundled-library and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread android-duplicate-class-kotlin-stdlib-or-bundled-library
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks