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

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'.

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 9
  • Comments: 41 (22 by maintainers)

Commits related to this issue

Most upvoted comments

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!

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.

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.

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).

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>

@XDarinor @tbalcom @wfhm

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

Please report here.

Thanks

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

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

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).