MAUI .NET 8 on Android - throwing an exception

Aneetha 65 Reputation points
2024-07-01T12:26:36.5066667+00:00

I have created a new MAUI .NET 8 project and migrated the Xamarin forms project code. When I tried to run the project with the Android device with Visual Studio Windows, which threw the exception below,

1>MSBUILD : java.exe error JAVA0000: Error in C:\Users\jeeva.nuget\packages\xamarin.androidx.collection.jvm\1.4.0.4\buildTransitive\net8.0-android34.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\jeeva.nuget\packages\xamarin.androidx.collection.jvm\1.4.0.4\buildTransitive\net8.0-android34.0....\jar\androidx.collection.collection-jvm.jar:androidx/collection/ArrayMapKt.class, C:\Users\jeeva.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\jeeva.nuget\packages\xamarin.androidx.collection.jvm\1.4.0.4\buildTransitive\net8.0-android34.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\jeeva.nuget\packages\xamarin.androidx.collection.jvm\1.4.0.4\buildTransitive\net8.0-android34.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


I have an in-app subscription in my project, and I used Xamarin.Android.Google.BillingClient package in migrated MAUI project.

<ItemGroup Condition="'$(TargetFramework)' == 'net8.0-android'">

  <PackageReference Include="Xamarin.Android.Google.BillingClient" Version="6.2.1" />

</ItemGroup>

Does this package cause this exception? is there any solution to resolve this issue?

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,607 questions
0 comments No comments
{count} votes

Accepted answer
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 76,551 Reputation points Microsoft Vendor
    2024-07-02T02:49:28.9066667+00:00

    Hello,

    Please add Xamarin.AndroidX.Fragment.Ktx and Xamarin.GooglePlayServices.Base in the <ItemGroup Condition="'$(TargetFramework)' == 'net8.0-android'">, then rebuild your project.

    <ItemGroup Condition="'$(TargetFramework)' == 'net8.0-android'">
    
            <PackageReference Include="Xamarin.Android.Google.BillingClient">
    
              <Version>6.2.1</Version>
    
            </PackageReference>
    
              <PackageReference Include="Xamarin.AndroidX.Fragment.Ktx">
    
                      <Version>1.7.0.2</Version>
    
                </PackageReference>
    
              <PackageReference Include="Xamarin.GooglePlayServices.Base" Version="118.4.0" />
    
          </ItemGroup>
    
    

    As note: My Microsoft.Maui.Controls and Microsoft.Maui.Controls.Compatibility version is 8.0.61

    Best Regards,

    Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

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

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.