TobiasBuchholz / Plugin.Firebase

Wrapper around the native Android and iOS Firebase Xamarin SDKs
MIT License
220 stars 49 forks source link

Type is defined multiple times build issue #172

Closed Noobicle closed 5 months ago

Noobicle commented 1 year ago

Hello,

I've been using the crashalytics plugin with great sucess(Thank you!). On installing the analytics plugin I am getting the following error;


Error in obj\Debug\net7.0-android33.0\lp\233\jl\classes.jar:com/google/android/gms/internal/measurement/zzef.class:
Type com.google.android.gms.internal.measurement.zzef is defined multiple times: obj\Debug\net7.0-android33.0\lp\233\jl\classes.jar:com/google/android/gms/internal/measurement/zzef.class, obj\Debug\net7.0-android33.0\lp\261\jl\classes.jar:com/google/android/gms/internal/measurement/zzef.class
Compilation failed
java.lang.RuntimeException: com.android.tools.r8.CompilationFailedException: Compilation failed to complete, origin: obj\Debug\net7.0-android33.0\lp\233\jl\classes.jar
com/google/android/gms/internal/measurement/zzef.class
    at com.android.tools.r8.internal.Fj.a(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:98)
    at com.android.tools.r8.D8.main(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:4)
Caused by: com.android.tools.r8.CompilationFailedException: Compilation failed to complete, origin: obj\Debug\net7.0-android33.0\lp\233\jl\classes.jar:com/google/android/gms/internal/measurement/zzef.class
    at Version.fakeStackEntry(Version_3.3.75.java:0)
<Removed>

Directory 'obj\Debug\net7.0-android33.0\lp\233' is from 'play-services-measurement-sdk-api.aar'.    

I've found the conflict appears to be between the MauiMTAdmob(https://github.com/marcojak/MauiMTAdmob) plugin and your analytics plugin.

I've tried googling to no avail do you have any recommendation on how I can fix this?

I'm quite new to MAUI/Xamarin so please forgive me if it's a really obvious solution.

Kapusch commented 1 year ago

When restoring the NuGet packages, did you notice any particular warning ?

Noobicle commented 1 year ago

Sadly not. It all progresses correctly no warnings given. Until the build error that is.

TobiasBuchholz commented 1 year ago

Sorry, for now I didn't find an solution for this issue but I was able to reproduce it with the sample project of the plugin, so when I've got time I'll take a look into it again. Until then please let us know in case you find a solution by yourself.

Noobicle commented 1 year ago

Thank you for responding. It makes me happy to know it's reproducible!

I will update if I find the solution.

Sorry for the hassle and thank you for the great work.

Edit: Created a minimum repo if it helps anyone find the answer. https://github.com/Noobicle/MauiBuildErrorMin

jeff-eats-pubsubs commented 1 year ago

Just got this error and deleted my bin and obj folders from root and built again. So far so good after that. Credit where credit is due.. Sorry I can't remember the exact question where/why this was recommended but this guy is on top of it.

Noobicle commented 1 year ago

Delete bin and obj folders from root and build again

Already tried the basics but thank you :).

jeff-eats-pubsubs commented 1 year ago

I am a noob lol. Was worth mentioning. Sorry no luck

Noobicle commented 1 year ago

Aren't we all :)

jeff-eats-pubsubs commented 1 year ago

MAUI is a beast. Good luck out there

TobiasBuchholz commented 1 year ago

Since I haven't heard from you in more than 30 days, I hope this issue is no longer affecting you. If it is, please reopen this issue and provide the more information so that I can look into it further. Thank you!

cagriy commented 12 months ago

I am having the same issue @TobiasBuchholz , albeit slightly different error message:

0>: Error JAVA0000 java: Error in /Users/cagri/.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:
Type androidx.collection.ArrayMapKt is defined multiple times: /Users/cagri/.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, /Users/cagri/.nuget/packages/xamarin.androidx.collection.ktx/1.2.0.5/buildTransitive/net6.0-android31.0/../../jar/androidx.collection.collection-ktx.jar:androidx/collection/ArrayMapKt.class
Compilation failed
java.lang.RuntimeException: com.android.tools.r8.CompilationFailedException: Compilation failed to complete, origin: /Users/cagri/.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
    at com.android.tools.r8.internal.Fj.a(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:98)
Noobicle commented 12 months ago

Since I haven't heard from you in more than 30 days, I hope this issue is no longer affecting you. If it is, please reopen this issue and provide the more information so that I can look into it further. Thank you!

Hey as far as I'm aware it's still an issue.

I was just patiently waiting for you to fix it. Didn't want to bug you, I sincerly appreciate the work you've done so far and didn't want to seem ungrateful because of a small bug.

cagriy commented 12 months ago

Can you reopen this issue @Noobicle ? As per Tobias's message above ?

Noobicle commented 12 months ago

Can you reopen this issue @Noobicle ? As per Tobias's message above ?

I'm not sure I can reopen it. At least I cannot find a option to do it anywhere.

TobiasBuchholz commented 12 months ago

I am having the same issue @TobiasBuchholz , albeit slightly different error message:

0>: Error JAVA0000 java: Error in /Users/cagri/.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:
Type androidx.collection.ArrayMapKt is defined multiple times: /Users/cagri/.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, /Users/cagri/.nuget/packages/xamarin.androidx.collection.ktx/1.2.0.5/buildTransitive/net6.0-android31.0/../../jar/androidx.collection.collection-ktx.jar:androidx/collection/ArrayMapKt.class
Compilation failed
java.lang.RuntimeException: com.android.tools.r8.CompilationFailedException: Compilation failed to complete, origin: /Users/cagri/.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
  at com.android.tools.r8.internal.Fj.a(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:98)

If you are using the newest version of the plugin this issue should be fixed by replacing

<ItemGroup Condition="'$(TargetFramework)' == 'net6.0-android'">
  <PackageReference Include="Xamarin.Kotlin.StdLib.Jdk7" Version="1.7.10" ExcludeAssets="build;buildTransitive" />
  <PackageReference Include="Xamarin.Kotlin.StdLib.Jdk8" Version="1.7.10" ExcludeAssets="build;buildTransitive" />
</ItemGroup>

with

<ItemGroup Condition="'$(TargetFramework)' == 'net6.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.Activity.Ktx" Version="1.8.0.1" />
</ItemGroup>

in your .csproj file.

@Noobicle ok, I'll reopen the issue then.

TobiasBuchholz commented 12 months ago

Hey @Noobicle, I was able to resolve your build error by updating the underlying Xamarin.Firebase.Analytics to the newest version. This is now released with Pluging.Firebase.Analytics 2.0.2 or Plugin.Firebase 2.0.8. Let me know if you still encounter any problems ✌️

cagriy commented 12 months ago

Hi @TobiasBuchholz , is the similar issue I mentioned above ok to be tracked on this issue ?

TobiasBuchholz commented 12 months ago

Hi @cagriy, if the suggested fix from above doesn't help, could you please provide a sample project that demonstrates your issue?

cagriy commented 12 months ago

@TobiasBuchholz , thank you. This didn't help. Here is a sample project: https://github.com/cagriy/FirebaseTest

I basically created a fresh .NET MAUI 7 project and only added Plugin.Firebase nugget. No other coding. It builds fine for iOS but fails on Android giving the following error:

image
tranb3r commented 12 months ago

@cagriy As mentioned in the documentation, you probably need to add this packages:

<ItemGroup Condition="'$(TargetFramework)' == 'net7.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.Activity.Ktx" Version="1.8.0.1" />
</ItemGroup>
TobiasBuchholz commented 12 months ago

Exactly, and don't forget to restore the packages after you've added them to the .csproj file, e.g. by running dotnet restore.

cagriy commented 12 months ago

@tranb3r , @TobiasBuchholz thanks for your help, and sorry for taking your time for something obvious.

vhugogarcia commented 12 months ago

Thanks friends for sharing how to solve this issue. I can confirm, I personally solved the BUILD issue on my .NET MAUI 8 projects by updating to the latest version of Plugin.Firebase.Analytics as mentioned by our friend @TobiasBuchholz, and applying the following ItemGroup on the .csproj file.

<ItemGroup Condition="'$(TargetFramework)' == 'net7.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.Activity.Ktx" Version="1.8.0.1" />
</ItemGroup>