Skip to content

Fix duplicate class errors for runtime-annotation-jvm and datastore-preferences-core-jvm - #1371

Merged
jonathanpeppers merged 1 commit into
mainfrom
fix/issue-1341-duplicate-jvm-classes
Mar 2, 2026
Merged

jonathanpeppers merged 1 commit into
mainfrom
fix/issue-1341-duplicate-jvm-classes

Conversation

@sheiksyedm

@sheiksyedm sheiksyedm commented Feb 27, 2026 •

Copy link
Copy Markdown
Contributor

Problem:

When R8/D8 code shrinker is enabled in Android/MAUI projects, the build fails with:

JAVA0000: Type androidx.compose.runtime.Immutable is defined multiple times:
xamarin.androidx.compose.runtime.annotation.android
xamarin.androidx.compose.runtime.annotation.jvm

JAVA0000: Type androidx.datastore.preferences.core.AtomicBoolean is defined multiple times

Root cause:

The Maven POMs for runtime-annotation and datastore-preferences-core declare their JVM variants as compile-scope dependencies. The binderator converts these into NuGet PackageReferences, causing both the Android (.aar) and JVM (.jar) variants to be pulled in simultaneously. R8/D8 then fails because the same Java classes exist in both.

Fix:

Added excludedRuntimeDependencies to prevent the JVM variant packages from being generated as NuGet dependencies of their parent packages.

The Android (.aar) variant already contains all the necessary classes for Android builds. The JVM (.jar). variant is redundant on Android and causes the duplicate class conflict.

Impact

Users who previously needed to workaround this with:

<PackageReference Include="Xamarin.AndroidX.Compose.Runtime.Annotation.Jvm" Version="1.10.0.1" 
ExcludeAssets="all" />
<PackageReference Include="Xamarin.AndroidX.DataStore.Preferences.Core.Jvm" Version="1.2.0.1" 
ExcludeAssets="all" />

will no longer need this workaround after upgrading to the new package versions.

Fixes #1341

…references-core-jvm (#1341)

Exclude JVM variant packages as runtime dependencies from their parent
no-bindings packages to prevent duplicate class errors (JAVA0000) when
R8/D8 code shrinker is enabled in Android/MAUI projects.

- Xamarin.AndroidX.Compose.Runtime.Annotation (1.10.3.1): exclude
  androidx.compose.runtime.runtime-annotation-jvm as runtime dependency
- Xamarin.AndroidX.DataStore.Preferences.Core (1.2.0.2): exclude
  androidx.datastore.datastore-preferences-core-jvm as runtime dependency

The Maven POMs declare the JVM variant as a compile-scope dependency of
the parent artifact. The binderator was converting this into a NuGet
PackageReference, causing both the Android (.aar) and JVM (.jar) variants
to be included simultaneously, leading to:
  'Type androidx.compose.runtime.Immutable is defined multiple times'
  'Type androidx.compose.runtime.StableMarker is defined multiple times'
  'Type androidx.datastore.preferences.core.AtomicBoolean is defined multiple times'

Fixes #1341
Copilot AI review requested due to automatic review settings February 27, 2026 10:36

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adjusts binderator configuration to prevent JVM-variant artifacts from being pulled into Android builds as transitive NuGet dependencies, avoiding R8/D8 duplicate-class failures (notably for Compose runtime-annotation and DataStore datastore-preferences-core) as reported in #1341.

Changes:

  • Add excludedRuntimeDependencies rules to drop *-jvm artifacts from the parent packages’ runtime dependency lists.
  • Bump NuGet revisions for the affected parent packages to ship the dependency-graph fix.
  • Update component governance manifest and the artifact/version documentation to reflect the new NuGet versions.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
docs/artifact-list-with-versions.md Updates the published NuGet versions for the parent artifacts to reflect the revision bump.
config.json Adds excludedRuntimeDependencies for the JVM variants and bumps nugetVersion revisions for the affected packages.
cgmanifest.json Updates tracked NuGet versions for component governance to match the new package revisions.

@jonathanpeppers
jonathanpeppers merged commit 473aec3 into main Mar 2, 2026
5 checks passed
@jonathanpeppers
jonathanpeppers deleted the fix/issue-1341-duplicate-jvm-classes branch March 2, 2026 14:24
MartinZikmund added a commit to unoplatform/uno.templates that referenced this pull request May 12, 2026
AppCompat 1.7.1.2 transitively pulls Compose.Runtime.Annotation 1.10.0.1,
which depends on both the .Android (AAR) and .Jvm (JAR) variants and
triggers an R8 duplicate-class error for androidx.compose.runtime.Immutable
on Android builds.

AppCompat 1.7.1.3 pulls Compose.Runtime.Annotation 1.10.4.1 transitively,
which contains the upstream fix (dotnet/android-libraries#1371) excluding
the JVM variant from Android targets.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
MartinZikmund added a commit to unoplatform/uno that referenced this pull request May 12, 2026
AppCompat 1.7.1.2 transitively pulls Compose.Runtime.Annotation 1.10.0.1,
which depends on both the .Android (AAR) and .Jvm (JAR) variants and
triggers an R8 duplicate-class error for androidx.compose.runtime.Immutable
on Android builds:

  java error JAVA0000: Type androidx.compose.runtime.Immutable is defined
  multiple times: xamarin.androidx.compose.runtime.annotation.android ...
  xamarin.androidx.compose.runtime.annotation.jvm ...

AppCompat 1.7.1.3 pulls Compose.Runtime.Annotation 1.10.4.1 transitively,
which contains the upstream fix (dotnet/android-libraries#1371) excluding
the JVM variant from Android targets.

Also bumps AndroidXActivity in Uno.Sdk/packages.json to 1.12.4.1 (matching
uno.templates) since AppCompat 1.7.1.3 transitively requires Activity
>= 1.12.4.1 - keeping the older pin would trigger NU1605 for downstream
Uno.Sdk consumers.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
MartinZikmund added a commit to unoplatform/uno that referenced this pull request May 12, 2026
Match the AppCompat version already pinned in Directory.Build.targets and
Uno.Sdk/packages.json so consumers restoring Uno.WinUI get the same
AndroidX binding surface (Compose.Runtime.Annotation 1.10.4.1, which
contains the upstream fix from dotnet/android-libraries#1371).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
MartinZikmund added a commit to unoplatform/uno.templates that referenced this pull request May 13, 2026
AppCompat 1.7.1.2 transitively pulls Compose.Runtime.Annotation 1.10.0.1,
which depends on both the .Android (AAR) and .Jvm (JAR) variants and
triggers an R8 duplicate-class error for androidx.compose.runtime.Immutable
on Android builds.

AppCompat 1.7.1.3 pulls Compose.Runtime.Annotation 1.10.4.1 transitively,
which contains the upstream fix (dotnet/android-libraries#1371) excluding
the JVM variant from Android targets.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
MartinZikmund added a commit to unoplatform/uno.templates that referenced this pull request May 13, 2026
AppCompat 1.7.1.2 transitively pulls Compose.Runtime.Annotation 1.10.0.1,
which depends on both the .Android (AAR) and .Jvm (JAR) variants and
triggers an R8 duplicate-class error for androidx.compose.runtime.Immutable
on Android builds.

AppCompat 1.7.1.3 pulls Compose.Runtime.Annotation 1.10.4.1 transitively,
which contains the upstream fix (dotnet/android-libraries#1371) excluding
the JVM variant from Android targets.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
MartinZikmund added a commit to unoplatform/uno.templates that referenced this pull request May 13, 2026
AppCompat 1.7.1.2 transitively pulls Compose.Runtime.Annotation 1.10.0.1,
which depends on both the .Android (AAR) and .Jvm (JAR) variants and
triggers an R8 duplicate-class error for androidx.compose.runtime.Immutable
on Android builds.

AppCompat 1.7.1.3 pulls Compose.Runtime.Annotation 1.10.4.1 transitively,
which contains the upstream fix (dotnet/android-libraries#1371) excluding
the JVM variant from Android targets.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
MartinZikmund added a commit to unoplatform/uno that referenced this pull request May 28, 2026
AppCompat 1.7.1.2 transitively pulls Compose.Runtime.Annotation 1.10.0.1,
which depends on both the .Android (AAR) and .Jvm (JAR) variants and
triggers an R8 duplicate-class error for androidx.compose.runtime.Immutable
on Android builds:

  java error JAVA0000: Type androidx.compose.runtime.Immutable is defined
  multiple times: xamarin.androidx.compose.runtime.annotation.android ...
  xamarin.androidx.compose.runtime.annotation.jvm ...

AppCompat 1.7.1.3 pulls Compose.Runtime.Annotation 1.10.4.1 transitively,
which contains the upstream fix (dotnet/android-libraries#1371) excluding
the JVM variant from Android targets.

Also bumps AndroidXActivity in Uno.Sdk/packages.json to 1.12.4.1 (matching
uno.templates) since AppCompat 1.7.1.3 transitively requires Activity
>= 1.12.4.1 - keeping the older pin would trigger NU1605 for downstream
Uno.Sdk consumers.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
MartinZikmund added a commit to unoplatform/uno that referenced this pull request May 28, 2026
Match the AppCompat version already pinned in Directory.Build.targets and
Uno.Sdk/packages.json so consumers restoring Uno.WinUI get the same
AndroidX binding surface (Compose.Runtime.Annotation 1.10.4.1, which
contains the upstream fix from dotnet/android-libraries#1371).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Xamarin.AndroidX.Activity: androidx.compose.runtime.Immutable is defined multiple times

4 participants