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
- downgrade package due to https://github.com/xamarin/AndroidX/issues/717 https://github.com/xamarin/GooglePlayServicesComponents/issues/694 — committed to BerserkerDotNet/WorkoutTracker by BerserkerDotNet a year ago
- Move to .NET 8 and minor fixes (#9) * 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... — committed to BerserkerDotNet/WorkoutTracker by BerserkerDotNet a year ago
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:
and yes - please report here if workaround works.
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.
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.
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:
@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.
Package reference list:
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).