使用 Firebase 和 AndroidX 包时,由于 androidx.collection.ArraySetKt 的多个定义,.NET MAUI 项目中编译失败

问题描述 投票:0回答:1

首先,我对此完全是菜鸟。但我有一个正在构建的 MAUI 项目。但是,当尝试开始使用 Firebase 时,我遇到了一个问题,我花了 10 个小时进行谷歌搜索和 chaptGPTing。问题是,当我安装 nuget Xamarin.Firebase.Auth 时,在构建时出现以下错误。

Rebuild started at 21:42...
Restored C:\Users\denni\source\repos\ShadowWood\ShadowWood\ShadowWood.csproj (in 713 ms).
1>------ Rebuild All started: Project: ShadowWood, Configuration: Debug Any CPU ------
1>C:\Users\denni\source\repos\ShadowWood\ShadowWood\Models\Realm.cs(6,19,6,28): warning CS8618: Non-nullable property 'FoodValue' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
1>C:\Users\denni\source\repos\ShadowWood\ShadowWood\Models\Realm.cs(6,19,6,28): warning CS8618: Non-nullable property 'FoodValue' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
1>ShadowWood -> C:\Users\denni\source\repos\ShadowWood\ShadowWood\bin\Debug\net8.0-windows10.0.19041.0\win10-x64\ShadowWood.dll
1>Done building project "ShadowWood.csproj".
1>C:\Users\denni\source\repos\ShadowWood\ShadowWood\Models\Realm.cs(6,19,6,28): warning CS8618: Non-nullable property 'FoodValue' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
1>ShadowWood -> C:\Users\denni\source\repos\ShadowWood\ShadowWood\bin\Debug\net8.0-android\ShadowWood.dll
1>MSBUILD : java.exe error JAVA0000: Error in C:\Users\denni\.nuget\packages\xamarin.androidx.collection.jvm\1.4.0.5\buildTransitive\net8.0-android34.0\..\..\jar\androidx.collection.collection-jvm.jar:androidx/collection/ArraySetKt.class:
1>MSBUILD : java.exe error JAVA0000: Type androidx.collection.ArraySetKt is defined multiple times: C:\Users\denni\.nuget\packages\xamarin.androidx.collection.jvm\1.4.0.5\buildTransitive\net8.0-android34.0\..\..\jar\androidx.collection.collection-jvm.jar:androidx/collection/ArraySetKt.class, C:\Users\denni\.nuget\packages\xamarin.androidx.collection.ktx\1.2.0.9\buildTransitive\net6.0-android31.0\..\..\jar\androidx.collection.collection-ktx.jar:androidx/collection/ArraySetKt.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\denni\.nuget\packages\xamarin.androidx.collection.jvm\1.4.0.5\buildTransitive\net8.0-android34.0\..\..\jar\androidx.collection.collection-jvm.jar
1>MSBUILD : java.exe error JAVA0000: androidx/collection/ArraySetKt.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\denni\.nuget\packages\xamarin.androidx.collection.jvm\1.4.0.5\buildTransitive\net8.0-android34.0\..\..\jar\androidx.collection.collection-jvm.jar:androidx/collection/ArraySetKt.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.ArraySetKt is defined multiple times: C:\Users\denni\.nuget\packages\xamarin.androidx.collection.jvm\1.4.0.5\buildTransitive\net8.0-android34.0\..\..\jar\androidx.collection.collection-jvm.jar:androidx/collection/ArraySetKt.class, C:\Users\denni\.nuget\packages\xamarin.androidx.collection.ktx\1.2.0.9\buildTransitive\net6.0-android31.0\..\..\jar\androidx.collection.collection-ktx.jar:androidx/collection/ArraySetKt.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 "ShadowWood.csproj" -- FAILED.
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
========== Rebuild completed at 21:43 and took 01:21,711 minutes ==========

ChatGPT 可能让我走上了错误的道路,但似乎传递 nuget Xamarin.AndroidX.Collection.Jvm 和 Xamarin.AndroidX.Collection.Ktx 存在问题。我尝试将它们安装在最新版本中,并将以下代码添加到我的 .csproj 中。正如我在其他线程中看到的建议。但我无法完成这项工作...

<ItemGroup Condition="'$(TargetFramework)' == 'net8.0-android'">
  <PackageReference Include="Xamarin.Firebase.Auth" Version="122.3.1.3">
    <ExcludeAssets>build, runtime, compile</ExcludeAssets>
  </PackageReference>
  <PackageReference Include="Xamarin.AndroidX.Collection.Jvm" Version="1.4.2" />
  <PackageReference Include="Xamarin.AndroidX.Collection" Version="1.4.2" />
  <PackageReference Include="Xamarin.AndroidX.Collection.Ktx" Version="1.4.2" />
</ItemGroup>
firebase xamarin firebase-authentication xamarin.android maui
1个回答
0
投票

根据您在下面提供的错误日志,您还需要安装软件包Xamarin.AndroidX.Fragment.Ktx来解决问题。

1>MSBUILD : java.exe error JAVA0000: Error in C:\Users\denni\.nuget\packages\xamarin.androidx.collection.jvm\1.4.0.5\buildTransitive\net8.0-android34.0\..\..\jar\androidx.collection.collection-jvm.jar:androidx/collection/ArraySetKt.class:
1>MSBUILD : java.exe error JAVA0000: Type androidx.collection.ArraySetKt is defined multiple times: C:\Users\denni\.nuget\packages\xamarin.androidx.collection.jvm\1.4.0.5\buildTransitive\net8.0-android34.0\..\..\jar\androidx.collection.collection-jvm.jar:androidx/collection/ArraySetKt.class, C:\Users\denni\.nuget\packages\xamarin.androidx.collection.ktx\1.2.0.9\buildTransitive\net6.0-android31.0\..\..\jar\androidx.collection.collection-ktx.jar:androidx/collection/ArraySetKt.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\denni\.nuget\packages\xamarin.androidx.collection.jvm\1.4.0.5\buildTransitive\net8.0-android34.0\..\..\jar\androidx.collection.collection-jvm.jar
1>MSBUILD : java.exe error JAVA0000: androidx/collection/ArraySetKt.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:
© www.soinside.com 2019 - 2024. All rights reserved.