MAUI: Rebuild Error: Type androidx.collection.ArrayMapKt is defined multiple times

Sreejith Sreenivasan 1,001 Reputation points
2025-05-21T11:53:58.3166667+00:00

I am getting below error when rebuilding in release mode:

1>MSBUILD : java.exe error JAVA0000: Error in C:\Users\SREEJITH\.nuget\packages\xamarin.androidx.collection.jvm\1.3.0.1\buildTransitive\net6.0-android31.0\..\..\jar\androidx.collection.collection-jvm.jar:androidx/collection/ArrayMapKt.class:
1>MSBUILD : java.exe error JAVA0000: Type androidx.collection.ArrayMapKt is defined multiple times: C:\Users\SREEJITH\.nuget\packages\xamarin.androidx.collection.jvm\1.3.0.1\buildTransitive\net6.0-android31.0\..\..\jar\androidx.collection.collection-jvm.jar:androidx/collection/ArrayMapKt.class, C:\Users\SREEJITH\.nuget\packages\xamarin.androidx.collection.ktx\1.2.0.9\buildTransitive\net6.0-android31.0\..\..\jar\androidx.collection.collection-ktx.jar:androidx/collection/ArrayMapKt.class
1>MSBUILD : java.exe error JAVA0000: Compilation failed
1>MSBUILD : java.exe error JAVA0000: java.lang.RuntimeException: com.android.tools.r8.CompilationFailedException: Compilation failed to complete, origin: C:\Users\SREEJITH\.nuget\packages\xamarin.androidx.collection.jvm\1.3.0.1\buildTransitive\net6.0-android31.0\..\..\jar\androidx.collection.collection-jvm.jar
1>MSBUILD : java.exe error JAVA0000: androidx/collection/ArrayMapKt.class
1>MSBUILD : java.exe error JAVA0000:    at com.android.tools.r8.utils.S0.a(R8_8.2.33_429c93fd24a535127db6f4e2628eb18f2f978e02f99f55740728d6b22bef16dd:135)
1>MSBUILD : java.exe error JAVA0000:    at com.android.tools.r8.D8.main(R8_8.2.33_429c93fd24a535127db6f4e2628eb18f2f978e02f99f55740728d6b22bef16dd:5)
1>MSBUILD : java.exe error JAVA0000: Caused by: com.android.tools.r8.CompilationFailedException: Compilation failed to complete, origin: C:\Users\SREEJITH\.nuget\packages\xamarin.androidx.collection.jvm\1.3.0.1\buildTransitive\net6.0-android31.0\..\..\jar\androidx.collection.collection-jvm.jar:androidx/collection/ArrayMapKt.class
1>MSBUILD : java.exe error JAVA0000:    at Version.fakeStackEntry(Version_8.2.33.java:0)
1>MSBUILD : java.exe error JAVA0000:    at com.android.tools.r8.T.a(R8_8.2.33_429c93fd24a535127db6f4e2628eb18f2f978e02f99f55740728d6b22bef16dd:5)
1>MSBUILD : java.exe error JAVA0000:    at com.android.tools.r8.utils.S0.a(R8_8.2.33_429c93fd24a535127db6f4e2628eb18f2f978e02f99f55740728d6b22bef16dd:82)
1>MSBUILD : java.exe error JAVA0000:    at com.android.tools.r8.utils.S0.a(R8_8.2.33_429c93fd24a535127db6f4e2628eb18f2f978e02f99f55740728d6b22bef16dd:32)
1>MSBUILD : java.exe error JAVA0000:    at com.android.tools.r8.utils.S0.a(R8_8.2.33_429c93fd24a535127db6f4e2628eb18f2f978e02f99f55740728d6b22bef16dd:31)
1>MSBUILD : java.exe error JAVA0000:    at com.android.tools.r8.utils.S0.b(R8_8.2.33_429c93fd24a535127db6f4e2628eb18f2f978e02f99f55740728d6b22bef16dd:2)
1>MSBUILD : java.exe error JAVA0000:    at com.android.tools.r8.D8.a(R8_8.2.33_429c93fd24a535127db6f4e2628eb18f2f978e02f99f55740728d6b22bef16dd:42)
1>MSBUILD : java.exe error JAVA0000:    at com.android.tools.r8.D8.b(R8_8.2.33_429c93fd24a535127db6f4e2628eb18f2f978e02f99f55740728d6b22bef16dd:13)
1>MSBUILD : java.exe error JAVA0000:    at com.android.tools.r8.D8.a(R8_8.2.33_429c93fd24a535127db6f4e2628eb18f2f978e02f99f55740728d6b22bef16dd:40)
1>MSBUILD : java.exe error JAVA0000:    at com.android.tools.r8.utils.S0.a(R8_8.2.33_429c93fd24a535127db6f4e2628eb18f2f978e02f99f55740728d6b22bef16dd:122)
1>MSBUILD : java.exe error JAVA0000:    ... 1 more
1>MSBUILD : java.exe error JAVA0000: Caused by: com.android.tools.r8.utils.b: Type androidx.collection.ArrayMapKt is defined multiple times: C:\Users\SREEJITH\.nuget\packages\xamarin.androidx.collection.jvm\1.3.0.1\buildTransitive\net6.0-android31.0\..\..\jar\androidx.collection.collection-jvm.jar:androidx/collection/ArrayMapKt.class, C:\Users\SREEJITH\.nuget\packages\xamarin.androidx.collection.ktx\1.2.0.9\buildTransitive\net6.0-android31.0\..\..\jar\androidx.collection.collection-ktx.jar:androidx/collection/ArrayMapKt.class
1>MSBUILD : java.exe error JAVA0000:    at com.android.tools.r8.utils.Q2.a(R8_8.2.33_429c93fd24a535127db6f4e2628eb18f2f978e02f99f55740728d6b22bef16dd:21)
1>MSBUILD : java.exe error JAVA0000:    at com.android.tools.r8.utils.D2.a(R8_8.2.33_429c93fd24a535127db6f4e2628eb18f2f978e02f99f55740728d6b22bef16dd:54)
1>MSBUILD : java.exe error JAVA0000:    at com.android.tools.r8.utils.D2.a(R8_8.2.33_429c93fd24a535127db6f4e2628eb18f2f978e02f99f55740728d6b22bef16dd:10)
1>MSBUILD : java.exe error JAVA0000:    at java.base/java.util.concurrent.ConcurrentHashMap.merge(ConcurrentHashMap.java:2056)
1>MSBUILD : java.exe error JAVA0000:    at com.android.tools.r8.utils.D2.a(R8_8.2.33_429c93fd24a535127db6f4e2628eb18f2f978e02f99f55740728d6b22bef16dd:6)
1>MSBUILD : java.exe error JAVA0000:    at com.android.tools.r8.graph.m4$a.d(R8_8.2.33_429c93fd24a535127db6f4e2628eb18f2f978e02f99f55740728d6b22bef16dd:6)
1>MSBUILD : java.exe error JAVA0000:    at com.android.tools.r8.dex.c.a(R8_8.2.33_429c93fd24a535127db6f4e2628eb18f2f978e02f99f55740728d6b22bef16dd:61)
1>MSBUILD : java.exe error JAVA0000:    at com.android.tools.r8.dex.c.a(R8_8.2.33_429c93fd24a535127db6f4e2628eb18f2f978e02f99f55740728d6b22bef16dd:12)
1>MSBUILD : java.exe error JAVA0000:    at com.android.tools.r8.dex.c.a(R8_8.2.33_429c93fd24a535127db6f4e2628eb18f2f978e02f99f55740728d6b22bef16dd:9)
1>MSBUILD : java.exe error JAVA0000:    at com.android.tools.r8.D8.a(R8_8.2.33_429c93fd24a535127db6f4e2628eb18f2f978e02f99f55740728d6b22bef16dd:45)
1>MSBUILD : java.exe error JAVA0000:    at com.android.tools.r8.D8.d(R8_8.2.33_429c93fd24a535127db6f4e2628eb18f2f978e02f99f55740728d6b22bef16dd:17)
1>MSBUILD : java.exe error JAVA0000:    at com.android.tools.r8.D8.c(R8_8.2.33_429c93fd24a535127db6f4e2628eb18f2f978e02f99f55740728d6b22bef16dd:69)
1>MSBUILD : java.exe error JAVA0000:    at com.android.tools.r8.utils.S0.a(R8_8.2.33_429c93fd24a535127db6f4e2628eb18f2f978e02f99f55740728d6b22bef16dd:28)
1>MSBUILD : java.exe error JAVA0000:    ... 6 more
1>MSBUILD : java.exe error JAVA0000:
1>Done building project "MyApp.csproj" -- FAILED.
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
========== Rebuild completed at 04:53 PM and took 08:24.816 minutes ==========

Below is my NuGet package section in .csproj

<ItemGroup>
    <PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
    <PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiVersion)" />
    <PackageReference Include="Castle.Core" Version="5.1.1" />
    <PackageReference Include="Xamarin.AndroidX.Browser" Version="1.6.0.2" />
    <PackageReference Include="Controls.UserDialogs.Maui" Version="1.7.0" />
    <PackageReference Include="CommunityToolkit.Maui" Version="6.1.0" />
    <PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.1" />
    <PackageReference Include="FFImageLoadingCompat" Version="0.1.1" />
    <PackageReference Include="FFImageLoadingCompat.Maui" Version="0.1.1" />
    <PackageReference Include="FFImageLoadingCompat.Svg" Version="0.1.1" />
    <PackageReference Include="FFImageLoadingCompat.Svg.Maui" Version="0.1.1" />
    <PackageReference Include="FFImageLoadingCompat.Transformations" Version="0.1.1" />
    <PackageReference Include="Microsoft.AppCenter.Analytics" Version="5.0.2" />
    <PackageReference Include="Microsoft.AppCenter.Crashes" Version="5.0.2" />
    <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="7.0.0" />
    <PackageReference Include="NETStandard.Library" Version="2.0.3" />
    <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
    <PackageReference Include="Plugin.MediaManager.Forms" Version="1.2.2" />
    <PackageReference Include="Plugin.Permissions" Version="6.0.1" />
    <PackageReference Include="RGPopup.Maui" Version="1.0.2" />
    <PackageReference Include="sqlite-net-pcl" Version="1.8.116" />
    <PackageReference Include="Stripe.net" Version="42.3.0" />
    <PackageReference Include="Twilio" Version="6.11.0" />
    <PackageReference Include="Xam.Plugin.Connectivity" Version="3.2.0" />
    <PackageReference Include="Xam.Plugin.LatestVersionStore" Version="2.1.2" />
    <PackageReference Include="Xam.Plugin.Media" Version="6.0.2" />
    <PackageReference Include="Xam.Plugin.SimpleAudioPlayer" Version="1.6.0" />
    <PackageReference Include="Xamarin.Essentials" Version="1.8.0" />
    <PackageReference Include="Xamarin.Plugins.Clipboard" Version="2.3.0" />
    <PackageReference Include="Plugin.Firebase" Version="2.0.9" />
    <PackageReference Include="Plugin.Firebase.Crashlytics" Version="2.0.1" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net8.0-android'">
    <PackageReference Include="Controls.UserDialogs.Maui" Version="1.3.0">
    </PackageReference>
    <PackageReference Include="Plugin.CurrentActivity" Version="2.1.0.4">
    </PackageReference>
    <PackageReference Include="Xamarin.Google.Guava" Version="32.0.1">
    </PackageReference>
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net8.0-android'">
    <PackageReference Include="Xamarin.AndroidX.Core" Version="1.12.0.2" />
    <PackageReference Include="Xamarin.AndroidX.Collection" Version="1.3.0.1" />
    <!--<PackageReference Include="Xamarin.AndroidX.Collection.Ktx" Version="1.3.0.1" />-->
    <PackageReference Include="Xamarin.AndroidX.Fragment.Ktx" Version="1.6.2" />
    <PackageReference Include="Xamarin.AndroidX.Activity.Ktx" Version="1.8.0.1" />
    <PackageReference Include="Xamarin.AndroidX.Browser" Version="1.6.0.2" />
</ItemGroup>

I have tried adding Xamarin.AndroidX.Fragment.Ktx as per this thread, tried commenting the Xamarin.AndroidX.Collection.Ktx and added Xamarin.AndroidX.Collection.Ktx on the conditionless itemgroup to resolve this issue, but nothing works.

There is no issue in debug mode and I am able to run the project to physical devices. When I try to build the .aab file, I rebuild the project and at that time only I am getting this error.

Developer technologies | .NET | .NET MAUI
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  2. Michael Le (WICLOUD CORPORATION) 1,145 Reputation points Microsoft External Staff
    2025-08-13T06:07:01.03+00:00

    Hello,

    At the time of writing, .NET MAUI 8 is out of support. Please consider upgrading to .NET MAUI 9 or later for continued support and improvements.

    Back to the main point, you are encountering a build failure in a .NET MAUI (.NET 8) Android Release configuration due to duplicate classes between androidx.collection.jvm and androidx.collection.ktx artifacts. This issue does not manifest in Debug builds but causes a crash during D8/R8 processing in Release builds.

    The issue arises from the following:

    • Your project includes both Xamarin.AndroidX.Collection.Jvm (1.3.0.1, containing androidx.collection.collection-jvm.jar) and Xamarin.AndroidX.Collection.Ktx (1.2.0.9, containing androidx.collection.collection-ktx.jar).
    • Starting with AndroidX Collection 1.3.0, the library was rewritten in Kotlin, and the main artifact (collection-jvm) now includes Kotlin extensions, rendering collection-ktx redundant and causing class overlaps (e.g., ArrayMapKt).
    • Debug builds bypass this issue due to fast deployment and partial dexing, but Release builds perform full dexing and shrinking, exposing the conflict during AAB generation.

    Resolution

    Use Collection 1.3.x and Exclude Collection.Ktx (Recommended)

    1. Remove Direct References to Xamarin.AndroidX.Collection.Ktx: Ensure your .csproj file does not explicitly reference Xamarin.AndroidX.Collection.Ktx.
    2. Exclude Transitive Collection.Ktx Dependencies: Add the following to your .csproj to neutralize any transitive inclusion of Xamarin.AndroidX.Collection.Ktx:
         <ItemGroup Condition="'$(TargetFramework)' == 'net8.0-android'">
           <PackageReference Include="Xamarin.AndroidX.Collection.Ktx" Version="1.2.0.9" ExcludeAssets="all" PrivateAssets="all" />
         </ItemGroup>
      
    3. Update Related AndroidX KTX Packages: Ensure all AndroidX KTX packages (e.g., Xamarin.AndroidX.Fragment.Ktx, Xamarin.AndroidX.Activity.Ktx, Xamarin.AndroidX.Core.Ktx) are updated to their latest versions compatible with Xamarin.AndroidX.Collection 1.3.x. Older versions may transitively pull in collection-ktx 1.2.x, reintroducing the conflict.

    Downgrade to Collection 1.2.x

    If updating all dependencies is not feasible, downgrade to Xamarin.AndroidX.Collection 1.2.x to align with Xamarin.AndroidX.Collection.Ktx 1.2.x:

    <ItemGroup Condition="'$(TargetFramework)' == 'net8.0-android'">
      <PackageReference Include="Xamarin.AndroidX.Collection" Version="1.2.0.9" />
    </ItemGroup>
    

    Note: Avoid referencing Xamarin.AndroidX.Collection.Jvm 1.3.x. Plan to upgrade to 1.3.x and remove collection-ktx in the future.

    Additional Project Cleanup Recommendations

    To prevent further conflicts and ensure a clean build:

    1. Remove Duplicate Package References:
      • Your .csproj includes duplicate entries for Controls.UserDialogs.Maui (versions 1.7.0 and 1.3.0) and Xamarin.AndroidX.Browser. Retain only the latest version in the conditional ItemGroup for net8.0-android.
      • Example: Keep Controls.UserDialogs.Maui 1.7.0 if compatible with .NET 8.
    2. Remove Legacy Xamarin Packages:
      • Remove Xamarin.Essentials, as its functionality is included in Microsoft.Maui.Essentials for .NET MAUI.
      • Review Xam.Plugin.* packages (e.g., Media, Connectivity). Replace with MAUI-compatible alternatives or built-in APIs where possible, as these may pull in outdated AndroidX dependencies.

    Recommended .csproj Updates

    Update your .csproj as follows to align dependencies and eliminate conflicts:

    <ItemGroup Condition="'$(TargetFramework)' == 'net8.0-android'">
      <PackageReference Include="Controls.UserDialogs.Maui" Version="1.7.0" />
      <PackageReference Include="Plugin.CurrentActivity" Version="2.1.0.4" />
      <PackageReference Include="Xamarin.Google.Guava" Version="32.0.1" />
      <PackageReference Include="Xamarin.AndroidX.Core" Version="1.12.0.2" />
      <PackageReference Include="Xamarin.AndroidX.Collection" Version="1.3.0.1" />
      <PackageReference Include="Xamarin.AndroidX.Fragment.Ktx" Version="1.6.2" />
      <PackageReference Include="Xamarin.AndroidX.Activity.Ktx" Version="1.8.0.1" />
      <PackageReference Include="Xamarin.AndroidX.Browser" Version="1.6.0.2" />
      <PackageReference Include="Xamarin.AndroidX.Collection.Ktx" Version="1.2.0.9" ExcludeAssets="all" PrivateAssets="all" />
    </ItemGroup>
    

    Remove:

    <!-- Remove duplicate/unnecessary references -->
    <!-- <PackageReference Include="Xamarin.Essentials" Version="1.8.0" /> -->
    <!-- Remove any unconditional duplicates of Controls.UserDialogs.Maui or Xamarin.AndroidX.Browser -->
    

    Pre-build

    1. Delete the bin and obj folders for all projects in your solution.
    2. Clear NuGet caches:
         dotnet nuget locals all --clear
      
    3. Restore and rebuild in Release mode:
         dotnet restore
         dotnet build -c Release
      

    I hope this helps clarify your issue.

    References

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.