Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrading Xamarin.AndroidX.Lifecycle packages to version 2.6.1 makes the build fail for duplicated classes #717

Closed
XDarinor opened this issue Apr 6, 2023 · 41 comments

Comments

@XDarinor
Copy link

XDarinor commented Apr 6, 2023

Android application type

Classic Xamarin.Android (MonoAndroid12.0, etc.)

Affected platform version

Visual Studio 2022 Enterprise, Windows 11, Xamarin.Android, build tools Android 13

Description

Upgrading packages Xamarin.AndroidX.Lifecycle.Runtime from previous version to 2.6.1 causes a Java error:

Error in G:\NuGET\Packages\xamarin.androidx.lifecycle.common\2.6.1\buildTransitive\monoandroid12.0\..\..\jar\androidx.lifecycle.lifecycle-common.jar:androidx/lifecycle/DispatchQueue.class:
Type androidx.lifecycle.DispatchQueue is defined multiple times: G:\NuGET\Packages\xamarin.androidx.lifecycle.common\2.6.1\buildTransitive\monoandroid12.0\..\..\jar\androidx.lifecycle.lifecycle-common.jar:androidx/lifecycle/DispatchQueue.class, obj\Debug\130\lp\150\jl\classes.jar:androidx/lifecycle/DispatchQueue.class
Compilation failed

This will happen also if the update is triggered by updating another NuGet packaged that have a dependecy on Lifecycle packages, like Xamarin.AndroidX.Fragment

Steps to Reproduce

Open solution NuGet packages, then upgrade Lifecycle related packages.

Did you find any workaround?

Just to not update the NuGet packges makes the solution work again.

Relevant log output

Error in G:\NuGET\Packages\xamarin.androidx.lifecycle.common\2.6.1\buildTransitive\monoandroid12.0\..\..\jar\androidx.lifecycle.lifecycle-common.jar:androidx/lifecycle/DispatchQueue.class:
Type androidx.lifecycle.DispatchQueue is defined multiple times: G:\NuGET\Packages\xamarin.androidx.lifecycle.common\2.6.1\buildTransitive\monoandroid12.0\..\..\jar\androidx.lifecycle.lifecycle-common.jar:androidx/lifecycle/DispatchQueue.class, obj\Debug\130\lp\150\jl\classes.jar:androidx/lifecycle/DispatchQueue.class
Compilation failed
java.lang.RuntimeException: com.android.tools.r8.CompilationFailedException: Compilation failed to complete, origin: G:\NuGET\Packages\xamarin.androidx.lifecycle.common\2.6.1\buildTransitive\monoandroid12.0\..\..\jar\androidx.lifecycle.lifecycle-common.jar
androidx/lifecycle/DispatchQueue.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: G:\NuGET\Packages\xamarin.androidx.lifecycle.common\2.6.1\buildTransitive\monoandroid12.0\..\..\jar\androidx.lifecycle.lifecycle-common.jar:androidx/lifecycle/DispatchQueue.class
	at Version.fakeStackEntry(Version_3.3.75.java:0)
	at com.android.tools.r8.internal.Fj.a(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:75)
	at com.android.tools.r8.internal.Fj.a(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:28)
	at com.android.tools.r8.internal.Fj.a(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:27)
	at com.android.tools.r8.internal.Fj.b(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:2)
	at com.android.tools.r8.D8.a(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:22)
	at com.android.tools.r8.D8.a(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:17)
	at com.android.tools.r8.internal.Fj.a(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:85)
	... 1 more
Caused by: com.android.tools.r8.internal.f: Type androidx.lifecycle.DispatchQueue is defined multiple times: G:\NuGET\Packages\xamarin.androidx.lifecycle.common\2.6.1\buildTransitive\monoandroid12.0\..\..\jar\androidx.lifecycle.lifecycle-common.jar:androidx/lifecycle/DispatchQueue.class, obj\Debug\130\lp\150\jl\classes.jar:androidx/lifecycle/DispatchQueue.class
	at com.android.tools.r8.internal.JT.a(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:14)
	at com.android.tools.r8.internal.JT.a(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:22)
	at com.android.tools.r8.internal.HN.a(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:33)
	at com.android.tools.r8.internal.HN.a(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:10)
	at java.base/java.util.concurrent.ConcurrentHashMap.merge(ConcurrentHashMap.java:2048)
	at com.android.tools.r8.internal.HN.a(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:6)
	at com.android.tools.r8.graph.B2$a.e(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:4)
	at com.android.tools.r8.dex.b.a(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:110)
	at com.android.tools.r8.dex.b.a(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:28)
	at com.android.tools.r8.D8.a(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:25)
	at com.android.tools.r8.D8.d(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:606)
	at com.android.tools.r8.D8.c(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:1)
	at com.android.tools.r8.internal.Fj.a(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:24)
	... 5 more
Directory 'obj\Debug\130\lp\150' is from 'androidx.lifecycle.lifecycle-runtime-ktx.aar'.
@moljac
Copy link
Contributor

moljac commented Apr 13, 2023

Thanks for reporting. Do you have repro sample or at least <PackageReference> list

@tbalcom
Copy link

tbalcom commented Apr 19, 2023

I'm seeing the same DispatchQueue error while attempting to update Xamarin.AndroidX.Work.Runtime from 2.7.1.6 to 2.8.1. Here is my <PackageReference> list for the Android project:

    <PackageReference Include="Microsoft.AppCenter.Analytics" Version="5.0.1" />
    <PackageReference Include="Microsoft.AppCenter.Crashes" Version="5.0.1" />
    <PackageReference Include="Microsoft.AppCenter.Distribute" Version="5.0.1" />
    <PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
    <PackageReference Include="MvvmCross" Version="8.0.2" />
    <PackageReference Include="MvvmCross.DroidX.Material" Version="8.0.2" />
    <PackageReference Include="MvvmCross.DroidX.RecyclerView" Version="8.0.2" />
    <PackageReference Include="MvvmCross.Plugin.Messenger" Version="8.0.2" />
    <PackageReference Include="MvvmCross.Plugin.ResxLocalization" Version="8.0.2" />
    <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
    <PackageReference Include="Serilog" Version="2.12.0" />
    <PackageReference Include="Serilog.Extensions.Logging" Version="3.1.0" />
    <PackageReference Include="Serilog.Formatting.Compact" Version="1.1.0" />
    <PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
    <PackageReference Include="Serilog.Sinks.Xamarin" Version="1.0.0" />
    <PackageReference Include="sqlite-net-pcl" Version="1.8.116" />
    <PackageReference Include="System.Net.Http" Version="4.3.4" />
    <PackageReference Include="Xamarin.AndroidX.Core.SplashScreen" Version="1.0.0.3" />
    <PackageReference Include="Xamarin.AndroidX.Preference" Version="1.2.0.4" />
    <PackageReference Include="Xamarin.AndroidX.Work.Runtime" Version="2.7.1.6" />
    <PackageReference Include="Xamarin.AndroidX.ConstraintLayout" Version="2.1.4.3" />
    <PackageReference Include="Xamarin.AndroidX.CardView" Version="1.0.0.18" />
    <PackageReference Include="Xamarin.Essentials" Version="1.7.5" />
    <PackageReference Include="Xamarin.Firebase.Messaging" Version="123.1.1.1" />
    <PackageReference Include="Xamarin.Google.Android.Material" Version="1.8.0" />
    <PackageReference Include="Xamarin.Google.Dagger" Version="2.44.2.1" />
    <PackageReference Include="Xamarin.GooglePlayServices.Location" Version="120.0.0.1" />
    <PackageReference Include="Xamarin.GooglePlayServices.Maps" Version="118.1.0.1" />
    <PackageReference Include="Xamarin.Kotlin.StdLib.Jdk8" Version="1.8.10" />
    <PackageReference Include="ZXing.Net.Mobile" Version="3.1.0-beta2" />

@XDarinor
Copy link
Author

Thanks for reporting. Do you have repro sample or at least <PackageReference> list

I'm sorry for the late answer. I don't have a repro sample, but I can share the PackageReferences below:

<ItemGroup>
    <PackageReference Include="Microsoft.AppCenter.Analytics">
      <Version>5.0.1</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.AppCenter.Crashes">
      <Version>5.0.1</Version>
    </PackageReference>
    <PackageReference Include="NLog">
      <Version>5.1.3</Version>
    </PackageReference>
    <PackageReference Include="Polly">
      <Version>7.2.3</Version>
    </PackageReference>
    <PackageReference Include="Syncfusion.Licensing">
      <Version>21.1.38</Version>
    </PackageReference>
    <PackageReference Include="Syncfusion.Xamarin.SfAutoComplete.Android">
      <Version>21.1.38</Version>
    </PackageReference>
    <PackageReference Include="Syncfusion.Xamarin.SfRotator.Android">
      <Version>21.1.38</Version>
    </PackageReference>
    <PackageReference Include="Syncfusion.Xamarin.SfSchedule.Android">
      <Version>21.1.38</Version>
    </PackageReference>
    <PackageReference Include="Syncfusion.Xamarin.SfTreeView.Android">
      <Version>21.1.38</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.Android.Support.v7.RecyclerView">
      <Version>28.0.0.3</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.AndroidX.AppCompat">
      <Version>1.6.0.1</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.AndroidX.Fragment">
      <Version>1.5.5.1</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.AndroidX.Legacy.Support.Core.UI">
      <Version>1.0.0.17</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.AndroidX.Lifecycle.LiveData">
      <Version>2.5.1.2</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.AndroidX.Migration">
      <Version>1.0.10</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.AndroidX.Navigation.Fragment">
      <Version>2.5.3.1</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.AndroidX.Navigation.Runtime">
      <Version>2.5.3.1</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.AndroidX.Navigation.UI">
      <Version>2.5.3.1</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.AndroidX.Startup.StartupRuntime">
      <Version>1.1.1.4</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.Essentials" Version="1.7.5" />
    <PackageReference Include="Xamarin.Google.Android.DataTransport.TransportBackendCct">
      <Version>3.1.8.1</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.Google.Android.DataTransport.TransportRuntime">
      <Version>3.1.8.1</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.Google.Android.Material">
      <Version>1.8.0</Version>
    </PackageReference>
    <PackageReference Include="Realm">
      <Version>10.21.0</Version>
    </PackageReference>
    <PackageReference Include="Newtonsoft.Json">
      <Version>13.0.3</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.Firebase.Messaging">
      <Version>123.1.1.1</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.Google.Dagger">
      <Version>2.44.2.1</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.GooglePlayServices.Base">
      <Version>118.1.0.1</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.Identity.Client">
      <Version>4.52.0</Version>
    </PackageReference>
  </ItemGroup>

Do you think this is enough? What also is needed?

@moljac
Copy link
Contributor

moljac commented Apr 20, 2023

@XDarinor @tbalcom

Thanks for the lists. I will try to make repro sample[s] out of those.

@moljac
Copy link
Contributor

moljac commented Apr 20, 2023

I'm sorry for the late answer. I don't have a repro sample, but I can share the PackageReferences below:

It is OK. Thanks

Do you think this is enough? What also is needed?

I hope so. Usually it is versions mismatch of the transitive dependencies.

@moljac
Copy link
Contributor

moljac commented Apr 21, 2023

possibly related

#634

xamarin/GooglePlayServicesComponents#694

@moljac
Copy link
Contributor

moljac commented Apr 21, 2023

Workaround to test

xamarin/GooglePlayServicesComponents#694 (comment)

@tbalcom
Copy link

tbalcom commented Apr 21, 2023

The workaround didn't help. I've also tried explicitly referencing the latest Xamarin.AndroidX.Lifecycle (Common, Common.Java8, Extensions) packages with no success.

@tbalcom
Copy link

tbalcom commented Apr 21, 2023

The full error:

Error in C:\Users\Trevor\.nuget\packages\xamarin.androidx.lifecycle.common\2.6.1\buildTransitive\monoandroid12.0\..\..\jar\androidx.lifecycle.lifecycle-common.jar:androidx/lifecycle/DispatchQueue.class:
Type androidx.lifecycle.DispatchQueue is defined multiple times: C:\Users\Trevor\.nuget\packages\xamarin.androidx.lifecycle.common\2.6.1\buildTransitive\monoandroid12.0\..\..\jar\androidx.lifecycle.lifecycle-common.jar:androidx/lifecycle/DispatchQueue.class, obj\Debug\130\lp\161\jl\classes.jar:androidx/lifecycle/DispatchQueue.class
Compilation failed
java.lang.RuntimeException: com.android.tools.r8.CompilationFailedException: Compilation failed to complete, origin: C:\Users\Trevor\.nuget\packages\xamarin.androidx.lifecycle.common\2.6.1\buildTransitive\monoandroid12.0\..\..\jar\androidx.lifecycle.lifecycle-common.jar
androidx/lifecycle/DispatchQueue.class
	at com.android.tools.r8.internal.Fj.a(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:98)
	at com.android.tools.r8.R8.main(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:4)
Caused by: com.android.tools.r8.CompilationFailedException: Compilation failed to complete, origin: C:\Users\Trevor\.nuget\packages\xamarin.androidx.lifecycle.common\2.6.1\buildTransitive\monoandroid12.0\..\..\jar\androidx.lifecycle.lifecycle-common.jar:androidx/lifecycle/DispatchQueue.class
	at Version.fakeStackEntry(Version_3.3.75.java:0)
	at com.android.tools.r8.internal.Fj.a(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:75)
	at com.android.tools.r8.internal.Fj.a(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:28)
	at com.android.tools.r8.internal.Fj.a(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:27)
	at com.android.tools.r8.R8.b(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:1133)
	at com.android.tools.r8.R8.a(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:2212)
	at com.android.tools.r8.internal.Fj.a(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:85)
	... 1 more
Caused by: com.android.tools.r8.internal.f: Type androidx.lifecycle.DispatchQueue is defined multiple times: C:\Users\Trevor\.nuget\packages\xamarin.androidx.lifecycle.common\2.6.1\buildTransitive\monoandroid12.0\..\..\jar\androidx.lifecycle.lifecycle-common.jar:androidx/lifecycle/DispatchQueue.class, obj\Debug\130\lp\161\jl\classes.jar:androidx/lifecycle/DispatchQueue.class
	at com.android.tools.r8.internal.JT.a(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:14)
	at com.android.tools.r8.internal.JT.a(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:22)
	at com.android.tools.r8.internal.HN.a(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:33)
	at com.android.tools.r8.internal.HN.a(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:10)
	at java.base/java.util.concurrent.ConcurrentHashMap.merge(ConcurrentHashMap.java:2048)
	at com.android.tools.r8.internal.HN.a(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:6)
	at com.android.tools.r8.graph.B2$a.e(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:4)
	at com.android.tools.r8.dex.b.a(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:110)
	at com.android.tools.r8.dex.b.a(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:28)
	at com.android.tools.r8.R8.a(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:902)
	at com.android.tools.r8.R8.a(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:2211)
	at com.android.tools.r8.internal.Fj.a(R8_3.3.75_b7a6ff6b13548611571508fe72282c9167faa649161ca0013edfc92e19bd7e58:24)
	... 4 more
Directory 'obj\Debug\130\lp\161' is from 'androidx.lifecycle.lifecycle-runtime-ktx.aar'.

@moljac
Copy link
Contributor

moljac commented Apr 24, 2023

@XDarinor

This is big problem:

		<PackageReference Include="Xamarin.Android.Support.v7.RecyclerView">
		<Version>28.0.0.3</Version>
		</PackageReference>

Android support libraries are not supported anymore.

@XDarinor
Copy link
Author

@XDarinor

This is big problem:


		<PackageReference Include="Xamarin.Android.Support.v7.RecyclerView">

		<Version>28.0.0.3</Version>

		</PackageReference>

Android support libraries are not supported anymore.

Mmm this could be a great issue. I think this package could be needed for the Syncfusion Treeview. I will try tomorrow to remove it and see if everything works out.

@moljac
Copy link
Contributor

moljac commented Apr 25, 2023

@XDarinor

Mmm this could be a great issue.

I'm not telling this is the root cause, but Android Support causes issues with modern apps which use AndroidX.

I think this package could be needed for the Syncfusion Treeview.

Could be. Try updating Treeview. Though I think you should not need to add some dependency for Treeview manually.

Or try removing Xamarin.Android.Support.v7.RecyclerView and see what screams with errors.

I will try tomorrow to remove it and see if everything works out.

Great.

@wfhm
Copy link

wfhm commented Apr 26, 2023

Same here. Visual Studio for Mac 17.5.3 (build 15), MAUI net7.0 app.

/Users/vromanychev/Projects/PushwooshSDK.DotNet/Sample: Error JAVA0000: Error in /Users/vromanychev/.nuget/packages/xamarin.androidx.lifecycle.common/2.6.1/buildTransitive/net6.0-android31.0/../../jar/androidx.lifecycle.lifecycle-common.jar:androidx/lifecycle/DispatchQueue.class:
Type androidx.lifecycle.DispatchQueue is defined multiple times: /Users/vromanychev/.nuget/packages/xamarin.androidx.lifecycle.common/2.6.1/buildTransitive/net6.0-android31.0/../../jar/androidx.lifecycle.lifecycle-common.jar:androidx/lifecycle/DispatchQueue.class, obj/Debug/net7.0-android/lp/173/jl/classes.jar:androidx/lifecycle/DispatchQueue.class

Package reference list:

    <ItemGroup>
    <PackageReference Include="Xamarin.AndroidX.Core" Version="1.9.0.2" />
    <PackageReference Include="Xamarin.AndroidX.Arch.Core.Common" Version="2.2.0" />
    <PackageReference Include="Xamarin.AndroidX.Arch.Core.Runtime" Version="2.2.0" />
    <PackageReference Include="Xamarin.AndroidX.Activity" Version="1.7.0" />
    <PackageReference Include="Xamarin.AndroidX.Fragment" Version="1.5.6" />
    <PackageReference Include="Xamarin.AndroidX.Work.Runtime" Version="2.7.1.5" />
    <PackageReference Include="Xamarin.Firebase.Messaging" Version="123.1.1.1" />
    <PackageReference Include="Xamarin.Firebase.Iid" Version="121.1.0.8" />
    <PackageReference Include="Xamarin.Firebase.Common" Version="120.2.0.1" />
    <PackageReference Include="Xamarin.Firebase.Installations" Version="117.1.0.1" />
    <PackageReference Include="Xamarin.Firebase.Annotations" Version="116.1.0.1" />
    <PackageReference Include="Xamarin.GooglePlayServices.Basement" Version="118.1.0.2" />
    <PackageReference Include="Xamarin.GooglePlayServices.Base" Version="118.1.0.1" />
    <PackageReference Include="Xamarin.GooglePlayServices.CloudMessaging" Version="117.0.2.3" />
    <PackageReference Include="Xamarin.AndroidX.SwipeRefreshLayout" Version="1.1.0.11" />
    <PackageReference Include="Xamarin.AndroidX.ConstraintLayout" Version="2.1.4.3" />
  </ItemGroup>

It's a fresh project so I wasn't updating Xamarin.AndroidX.Work.Runtime, just added the 2.7.1.5 version. The workaround didn't help.

Directory 'obj/Debug/net7.0-android/lp/173' is from 'androidx.lifecycle.lifecycle-runtime-ktx.aar' (double-checked it with map.cache).

@tipa
Copy link

tipa commented Apr 26, 2023

The problem can be easily reproduced by simply adding these two dependencies:

Xamarin.AndroidX.Camera.Camera2 v1.2.2
Xamarin.AndroidX.Preference v1.2.0.4

AndroidApp1.zip

@wfhm
Copy link

wfhm commented Apr 27, 2023

@moljac
Got it working in my project by checking all transitive dependencies and manually downgrading conflicting packages to the following versions:

    <PackageReference Include="Xamarin.AndroidX.Core" Version="1.9.0.1" />
    <PackageReference Include="Xamarin.AndroidX.Arch.Core.Common" Version="2.1.0.16" />
    <PackageReference Include="Xamarin.AndroidX.Arch.Core.Runtime" Version="2.1.0.16" />
    <PackageReference Include="Xamarin.AndroidX.Activity" Version="1.6.1" />
    <PackageReference Include="Xamarin.AndroidX.Fragment" Version="1.5.5" />
    <PackageReference Include="Xamarin.AndroidX.Work.Runtime" Version="2.7.1.5" />
    <PackageReference Include="Xamarin.Firebase.Messaging" Version="123.0.8" />
    <PackageReference Include="Xamarin.Firebase.Iid" Version="121.1.0.7" />
    <PackageReference Include="Xamarin.Firebase.Common" Version="120.1.2" />
    <PackageReference Include="Xamarin.Firebase.Installations" Version="117.0.3" />
    <PackageReference Include="Xamarin.Firebase.Annotations" Version="116.1.0" />
    <PackageReference Include="Xamarin.GooglePlayServices.Basement" Version="118.1.0" />
    <PackageReference Include="Xamarin.GooglePlayServices.Base" Version="118.1.0" />
    <PackageReference Include="Xamarin.GooglePlayServices.CloudMessaging" Version="117.0.2.2" />
    <PackageReference Include="Xamarin.AndroidX.SwipeRefreshLayout" Version="1.1.0.10" />
    <PackageReference Include="Xamarin.AndroidX.ConstraintLayout" Version="2.1.4.2" />

Strange thing though is that .NET Android application compiled and ran just fine with the same packages that were causing build failure for MAUI app.

@moljac
Copy link
Contributor

moljac commented Apr 27, 2023

@moljac Got it working in my project by checking all transitive dependencies and manually downgrading conflicting packages to the following versions:

    <PackageReference Include="Xamarin.AndroidX.Core" Version="1.9.0.1" />
    <PackageReference Include="Xamarin.AndroidX.Arch.Core.Common" Version="2.1.0.16" />
    <PackageReference Include="Xamarin.AndroidX.Arch.Core.Runtime" Version="2.1.0.16" />
    <PackageReference Include="Xamarin.AndroidX.Activity" Version="1.6.1" />
    <PackageReference Include="Xamarin.AndroidX.Fragment" Version="1.5.5" />
    <PackageReference Include="Xamarin.AndroidX.Work.Runtime" Version="2.7.1.5" />
    <PackageReference Include="Xamarin.Firebase.Messaging" Version="123.0.8" />
    <PackageReference Include="Xamarin.Firebase.Iid" Version="121.1.0.7" />
    <PackageReference Include="Xamarin.Firebase.Common" Version="120.1.2" />
    <PackageReference Include="Xamarin.Firebase.Installations" Version="117.0.3" />
    <PackageReference Include="Xamarin.Firebase.Annotations" Version="116.1.0" />
    <PackageReference Include="Xamarin.GooglePlayServices.Basement" Version="118.1.0" />
    <PackageReference Include="Xamarin.GooglePlayServices.Base" Version="118.1.0" />
    <PackageReference Include="Xamarin.GooglePlayServices.CloudMessaging" Version="117.0.2.2" />
    <PackageReference Include="Xamarin.AndroidX.SwipeRefreshLayout" Version="1.1.0.10" />
    <PackageReference Include="Xamarin.AndroidX.ConstraintLayout" Version="2.1.4.2" />

Strange thing though is that .NET Android application compiled and ran just fine with the same packages that were causing build failure for MAUI app.

This is usually how I do it, but it is not ideal, as you probably found out. I need to find a way to detect issue easier and even to suggest or implement fix.

@moljac
Copy link
Contributor

moljac commented Apr 27, 2023

Strange thing though is that .NET Android application compiled and ran just fine with the same packages that were causing build failure for MAUI app.

by .NET Android do you mean Xamarin classic?

Can you provide csproj?

@wfhm
Copy link

wfhm commented Apr 27, 2023

by .NET Android do you mean Xamarin classic?
I was talking about the one created with the default .NET Android template in Visual Studio:

Screenshot 2023-04-27 at 18 48 38

Can you provide csproj?

That might be a bit complicated. The whole solution is MAUI class library based on native Android (and iOS) bindings. Bindings are then wrapped in platform-specific class libraries, and these libraries are used as dependencies in a single MAUI class library.

I was testing Android class library with both .NET Android app and MAUI app, and for MAUI it didn't work as expected.

Android library csproj:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net7.0-android</TargetFramework>
    <SupportedOSPlatformVersion>21</SupportedOSPlatformVersion>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
  </PropertyGroup>
  <ItemGroup>
    <ProjectReference Include="..\PushwooshSDK.DotNet.Android.Bindings\PushwooshSDK.DotNet.Android.Bindings.csproj" />
    <ProjectReference Include="..\PushwooshSDK.DotNet.Core\PushwooshSDK.DotNet.Core.csproj" />
  </ItemGroup>
    <ItemGroup>
    <PackageReference Include="Xamarin.AndroidX.Core" Version="1.9.0.1" />
    <PackageReference Include="Xamarin.AndroidX.Arch.Core.Common" Version="2.1.0.16" />
    <PackageReference Include="Xamarin.AndroidX.Arch.Core.Runtime" Version="2.1.0.16" />
    <PackageReference Include="Xamarin.AndroidX.Activity" Version="1.6.1" />
    <PackageReference Include="Xamarin.AndroidX.Fragment" Version="1.5.5" />
    <PackageReference Include="Xamarin.AndroidX.Work.Runtime" Version="2.7.1.5" />
    <PackageReference Include="Xamarin.Firebase.Messaging" Version="123.0.8" />
    <PackageReference Include="Xamarin.Firebase.Iid" Version="121.1.0.7" />
    <PackageReference Include="Xamarin.Firebase.Common" Version="120.1.2" />
    <PackageReference Include="Xamarin.Firebase.Installations" Version="117.0.3" />
    <PackageReference Include="Xamarin.Firebase.Annotations" Version="116.1.0" />
    <PackageReference Include="Xamarin.GooglePlayServices.Basement" Version="118.1.0" />
    <PackageReference Include="Xamarin.GooglePlayServices.Base" Version="118.1.0" />
    <PackageReference Include="Xamarin.GooglePlayServices.CloudMessaging" Version="117.0.2.2" />
    <PackageReference Include="Xamarin.AndroidX.SwipeRefreshLayout" Version="1.1.0.10" />
    <PackageReference Include="Xamarin.AndroidX.ConstraintLayout" Version="2.1.4.2" />
  </ItemGroup>
</Project>

Android app csproj:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net7.0-android</TargetFramework>
    <SupportedOSPlatformVersion>21</SupportedOSPlatformVersion>
    <OutputType>Exe</OutputType>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
    <ApplicationId>com.pushwoosh.demoapp</ApplicationId>
    <ApplicationVersion>1</ApplicationVersion>
    <ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
  </PropertyGroup>
  <ItemGroup>
    <None Remove="google-services.json" />
  </ItemGroup>
  <ItemGroup>
    <GoogleServicesJson Include="google-services.json" />
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\PushwooshSDK.DotNet.Android.Library\PushwooshSDK.DotNet.Android.Library.csproj" />
  </ItemGroup>
</Project>

MAUI app currently uses multiplatform library, so I believe its csproj is of no use to you, but I also tested it by adding nuget packages directly to the project the same way as I described here.

Please let me know if you need more detail on it.

@SeanMollet
Copy link

I'm using .net 7 with the net7.0-android target and getting the same thing.

@moljac
Copy link
Contributor

moljac commented Apr 30, 2023

I was able to reproduce only

  1. @tipa's repro info
  2. @wfhm MAUI app
    false positive - different error - under investigation

I am currently blocked with MavenNet, so I'll bump all packages which might help without digging too deep into dependency forests.

@moljac
Copy link
Contributor

moljac commented May 1, 2023

@tipa

This seems to work:

    <PackageReference Include="Xamarin.AndroidX.Camera.Camera2" Version="1.2.2.1" />
    <PackageReference Include="Xamarin.AndroidX.Preference" Version="1.2.0.5" />

@tipa
Copy link

tipa commented May 2, 2023

@moljac Yes, updating to the latest versions resolved the issue for me. Thanks!

@moljac
Copy link
Contributor

moljac commented May 2, 2023

@XDarinor
@tbalcom
@wfhm

Try updating AX packages. Issue might persist if GPS-FB-MLKit package pulls in older dependencies.

Please report here.

Thanks

@tbalcom
Copy link

tbalcom commented May 2, 2023

Everything is working well now after the recent NuGet package updates. Thanks for the help!

These versions are working together now:

<ItemGroup>
    <PackageReference Include="Microsoft.AppCenter.Analytics" Version="5.0.1" />
    <PackageReference Include="Microsoft.AppCenter.Crashes" Version="5.0.1" />
    <PackageReference Include="Microsoft.AppCenter.Distribute" Version="5.0.1" />
    <PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
    <PackageReference Include="MvvmCross" Version="8.0.2" />
    <PackageReference Include="MvvmCross.DroidX.Material" Version="8.0.2" />
    <PackageReference Include="MvvmCross.DroidX.RecyclerView" Version="8.0.2" />
    <PackageReference Include="MvvmCross.Plugin.Messenger" Version="8.0.2" />
    <PackageReference Include="MvvmCross.Plugin.ResxLocalization" Version="8.0.2" />
    <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
    <PackageReference Include="Serilog" Version="2.12.0" />
    <PackageReference Include="Serilog.Extensions.Logging" Version="3.1.0" />
    <PackageReference Include="Serilog.Formatting.Compact" Version="1.1.0" />
    <PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
    <PackageReference Include="Serilog.Sinks.Xamarin" Version="1.0.0" />
    <PackageReference Include="sqlite-net-pcl" Version="1.8.116" />
    <PackageReference Include="System.Net.Http" Version="4.3.4" />
    <PackageReference Include="Xamarin.AndroidX.Core.SplashScreen" Version="1.0.0.4" />
    <PackageReference Include="Xamarin.AndroidX.Preference" Version="1.2.0.5" />
    <PackageReference Include="Xamarin.AndroidX.Work.Runtime" Version="2.8.1.1" />
    <PackageReference Include="Xamarin.AndroidX.ConstraintLayout" Version="2.1.4.4" />
    <PackageReference Include="Xamarin.AndroidX.CardView" Version="1.0.0.19" />
    <PackageReference Include="Xamarin.Essentials" Version="1.7.5" />
    <PackageReference Include="Xamarin.Firebase.Messaging" Version="123.1.1.1" />
    <PackageReference Include="Xamarin.Google.Android.Material" Version="1.8.0.1" />
    <PackageReference Include="Xamarin.GooglePlayServices.Location" Version="120.0.0.1" />
    <PackageReference Include="Xamarin.GooglePlayServices.Maps" Version="118.1.0.1" />
    <PackageReference Include="ZXing.Net.Mobile" Version="3.1.0-beta2" />
</ItemGroup>

@moljac
Copy link
Contributor

moljac commented May 12, 2023

@XDarinor
@wfhm

Any news?

@XDarinor
Copy link
Author

@XDarinor @wfhm

Any news?

I've upgraded now our project and it builds. The issue seems solved for me.

@moljac
Copy link
Contributor

moljac commented May 12, 2023

@wfhm ??

I've upgraded now our project and it builds. The issue seems solved for me.

There might be issues (slight probability) with GPS-FB-MLKit dependencies, but I am working on it.

@wfhm
Copy link

wfhm commented May 12, 2023

@moljac sorry for the delay. We had published nupkg with older dependency versions, but I’ve checked the new versions and it seems to be working fine. Thanks!

@moljac
Copy link
Contributor

moljac commented May 12, 2023

@moljac sorry for the delay.

It is OK. Just wanted to know.

We had published nupkg with older dependency versions, but I’ve checked the new versions and it seems to be working fine. Thanks!

You are welcome.

@moljac
Copy link
Contributor

moljac commented May 12, 2023

Closing this issue

@moljac moljac closed this as completed May 12, 2023
@sphix0108
Copy link

Hi,
I encountered the similar problem with: Type androidx.lifecycle.DispatchQueue is defined mutiple times.
How to check the dependencies that causes the error?

@moljac
Copy link
Contributor

moljac commented May 16, 2023

Hi, I encountered the similar problem with: Type androidx.lifecycle.DispatchQueue is defined mutiple times.

Just update all dependencies to latest. Note: GPS-FB-MLKit or other 3rd party package might still cause issues. Namely GPS-FB-MLKit is not yet "aligned", so particular dependency could pull in problematic older packages and issue could be hit again.

How to check the dependencies that causes the error?

It is not that easy. In some cases Xamarin.AndroidX.Lifecycle.*, but in other cases combination of any could cause problems (check tipa's dependencies in this issue).

@sphix0108
Copy link

sphix0108 commented May 19, 2023

Thanks for your reply.
I am trying to use Xamarin.AndroidX.Biometric <= this one is culprit but I don't know how to/ which dependencies should be upgrade together with it. I am fairly new to MAUI/Xamarin and development in all.
If you have any suggestion, it will be very helpful. Thanks

@sphix0108
Copy link

sphix0108 commented May 19, 2023

Thanks for your reply. I am trying to use Xamarin.AndroidX.Biometric <= this one is culprit but I don't know how to/ which dependencies should be upgrade together with it.

I tried downgraded the the Xamarin.AndroidX.BioMetric and *.AndroidX.Core to the previous level (Biometric = 1.1.0.10 & Core = 1.8.0.1) then I can build the project successfully. Just for a report, since my project is approaching deadline, I cannot check more regarding this problem.
Thank you for your support.

BerserkerDotNet added a commit to BerserkerDotNet/WorkoutTracker that referenced this issue May 20, 2023
* fix width of the set indicator
fix persistance of the model when sets are updated
migrate to .NET 8

* fix width of the set indicator
fix persistance of the model when sets are updated
migrate to .NET 8

* run on windows

* package updates and using a flag

* no framework flag

* downgrade package due to dotnet/android-libraries#717
xamarin/GooglePlayServicesComponents#694
@moljac
Copy link
Contributor

moljac commented May 24, 2023

@Lsdenis
Copy link

Lsdenis commented May 31, 2023

Possible Workaround

I had a similar problem, but with another packages. So, basically this thread helped to understand the root of the problem.

Problem:

Type androidx.activity.OnBackPressedDispatcherKt is defined multiple times: 
  obj/Debug/net6.0-android33.0/lp/111/jl/classes.jar:androidx/activity/OnBackPressedDispatcherKt.class, 
  obj/Debug/net6.0-android33.0/lp/143/jl/classes.jar:androidx/activity/OnBackPressedDispatcherKt.class

I went into the both paths obj/Debug/net6.0-android33.0/lp/111/jl/ and obj/Debug/net6.0-android33.0/lp/143/jl/, checked the manifests inside and installed both libraries explicitly.
In my case they are:

Xamarin.AndroidX.Activity.Ktx
Xamarin.AndroidX.Activity

I performed a quick smoke test and looks like it work, but no guarantee yet.

Maybe it'll help someone :)

@moljac
Copy link
Contributor

moljac commented Jun 1, 2023

Possible Workaround

@Lsdenis

Thanks for the feedback.

I had a similar problem, but with another packages.

Yes it is about transitive dependencies and what gets referenced + google moving types around.

So, basically this thread helped to understand the root of the problem.

Problem:

Type androidx.activity.OnBackPressedDispatcherKt is defined multiple times: 
  obj/Debug/net6.0-android33.0/lp/111/jl/classes.jar:androidx/activity/OnBackPressedDispatcherKt.class, 
  obj/Debug/net6.0-android33.0/lp/143/jl/classes.jar:androidx/activity/OnBackPressedDispatcherKt.class

I went into the both paths obj/Debug/net6.0-android33.0/lp/111/jl/ and obj/Debug/net6.0-android33.0/lp/143/jl/, checked the manifests inside and installed both libraries explicitly. In my case they are:

Xamarin.AndroidX.Activity.Ktx
Xamarin.AndroidX.Activity

I performed a quick smoke test and looks like it work, but no guarantee yet.

It works on few other samples I am investigating. Still several to do.

Maybe it'll help someone :)

It did. Thanks

@moljac
Copy link
Contributor

moljac commented Jun 1, 2023

As temp workaround try explicitly adding following PackageReferences:

		<PackageReference Include="Xamarin.AndroidX.Activity" Version="1.7.2" />
		<PackageReference Include="Xamarin.AndroidX.Activity.Ktx" Version="1.7.2" />

and yes - please report here if workaround works.

@tklempay
Copy link

tklempay commented Jun 8, 2023

As temp workaround try explicitly adding following PackageReferences:

		<PackageReference Include="Xamarin.AndroidX.Activity" Version="1.7.2" />
		<PackageReference Include="Xamarin.AndroidX.Activity.Ktx" Version="1.7.2" />

and yes - please report here if workaround works.

In the process of porting a Xamarin native app (android and ios) to .NET MAUI. In the port of android, fixed all of the compilation errors only to hit this bug. Adding your explicit package references cleared up the error. Thanks!

@moljac
Copy link
Contributor

moljac commented Jun 11, 2023

@tklempay Thanks for the feedback!

@moljac
Copy link
Contributor

moljac commented Jul 9, 2023

Duplicates:

#717
#742
#747
#749

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

No branches or pull requests

9 participants