PC パソコン

How to Fix “Duplicate mapping with R8 9.1” in Android Studio

An Android Studio release build can fail while R8 reports Duplicate mapping. Google tracks “Duplicate mapping with R8 9.1” as Issue 522844908 and lists it as fixed in Android Gradle Plugin (AGP) 9.3.3. This article explains how to identify that mapping-generation defect, distinguish it from an ordinary duplicate-class problem, and move to the officially fixed toolchain.

Representative error

Execution failed for task ':app:minifyReleaseWithR8'.
...
Duplicate mapping
...
R8 9.1

The complete output may include the affected class, method, or mapping entries. Preserve the full log and confirm that minifyReleaseWithR8 and Duplicate mapping belong to the same failure.

Cause

R8 writes the relationship between original and obfuscated names to mapping.txt. Official Issue 522844908 describes an R8 9.1 defect that produces duplicate mappings, and Google marks it fixed in AGP 9.3.3. This is distinct from the common case where the same class is packaged by two dependencies.

Affected and fixed versions: The official entry identifies R8 9.1 and AGP 9.3.3 as the release containing the fix. The public release notes do not establish every affected R8 build number or claim that all inputs reproduce the problem.

Conditions

  • A release variant uses R8 shrinking, optimization, and obfuscation.
  • The log or toolchain metadata identifies R8 9.1.
  • The failure occurs while R8 generates or processes mapping data.
  • A debug or non-minified build may still succeed.

Recommended solution

1. Capture the complete stack trace

./gradlew assembleRelease --stacktrace --info

Record the failing task, AGP/R8 version, and duplicated entries. If the diagnostic actually says Duplicate class, investigate dependency duplication instead.

2. Upgrade to AGP 9.3.3 or later

[versions]
agp = "9.3.3"

[plugins]
android-application = { id = "com.android.application", version.ref = "agp" }

The official AGP 9.3 requirements are Gradle 9.5.0 or newer and JDK 17.

3. Align the Gradle Wrapper and JDK

./gradlew wrapper --gradle-version 9.5
./gradlew --version

Set both Android Studio’s Gradle JDK and CI’s JAVA_HOME to JDK 17.

4. Rebuild without stale outputs

./gradlew --stop
./gradlew clean
./gradlew assembleRelease
# For an app bundle:
./gradlew bundleRelease

Retain old mapping files for historical crash analysis, but do not mix them into the new build. Invalidate CI outputs produced by the older R8 version.

Alternatives

  • Temporarily pin the last successful AGP/R8 version: Use a toolchain already verified by the project if the upgrade cannot be completed immediately. This is not the permanent fix.
  • Disable minification for diagnosis: Comparing a build with minifyEnabled false can confirm that the failure depends on R8, but it changes size, performance, and obfuscation and is not the recommended production solution.
  • Check for duplicate dependencies when appropriate: If the log says Duplicate class, run ./gradlew :app:dependencies and resolve dependency duplication. That is a different issue from 522844908.

Verification

  1. Confirm Gradle and JVM versions with ./gradlew --version.
  2. Verify that the project resolves AGP 9.3.3 or later.
  3. Build the release APK/AAB from a clean checkout and in CI.
  4. Confirm that one new mapping.txt is generated and the build completes.
  5. Install the release build and use its exact mapping file for Retrace if needed.

Cautions

  • Do not confuse Duplicate mapping with Duplicate class.
  • Always upload and archive the mapping file produced by the exact app bundle or APK being distributed.
  • Updating AGP without satisfying its Gradle and JDK requirements can create a separate sync or build failure.

Summary

The known Duplicate mapping defect in R8 9.1 is fixed in AGP 9.3.3. Align AGP with Gradle 9.5.0 or newer and JDK 17, remove stale outputs, and verify that a clean release build generates a valid mapping file.

Official references