Android R8 "Program type already present" / "Missing class" in CI
R8 runs during minifyReleaseWithR8 to shrink and obfuscate the release build. It fails when two artifacts provide the same class ("Program type already present") or when a referenced class is absent and no rule keeps it ("Missing class").
What this error means
The release build fails in minifyReleaseWithR8 with "Type X is defined multiple times" / "Program type already present: X" or "Missing class X (referenced from: ...)".
> Execution failed for task ':app:minifyReleaseWithR8'.
> com.android.tools.r8.CompilationFailedException: Compilation failed to complete
> Program type already present: com.example.util.StringsCommon causes
A duplicate class from two dependencies
Two artifacts (often an old support library and its AndroidX equivalent) define the same class, so R8 sees it twice.
A referenced class missing without a keep rule
Code references a class that is not on the runtime classpath and no ProGuard/R8 keep rule retains or ignores it.
How to fix it
Remove the duplicate dependency
- Run the dependency report to find which artifacts provide the duplicate class.
- Exclude the obsolete one (for example a legacy support library).
- Re-run the release build.
./gradlew :app:dependencies --configuration releaseRuntimeClasspathAdd a keep or dontwarn rule for a missing class
For a benign missing reference, keep the class or suppress the warning in the R8 rules file.
-dontwarn com.example.optional.**
-keep class com.example.util.Strings { *; }How to prevent it
- Avoid mixing legacy support and AndroidX artifacts.
- Resolve duplicate classes by excluding the obsolete dependency.
- Keep R8 rules current for optional or reflective references.