Conflicting Nuget package in Xamarin.Forms project

49 Views Asked by At

I have a project that is using the Urban Airship API library. Everything was working well until I had to update the Urban Airship nuget. It seems that somewhere it or one of its dependencies references a xamarin.androidx.lifecycle.common.java8 nuget package while several parts of Xamarin.Forms a xamarin.androidx.lifecycle.common nuget package. The problem there seems to be a class file collision on a androidx.lifecycle.DefaultLifecycleObserver java class between the two nuget packages. Yes I MAUI is out and I probably should be getting away from Xamarin.Forms like it is a sinking ship and in an ideal situation I would be upgrading to MAUI, but, that would be quite intensive for this particular project. And the decision makers are not 100% sure on whether or not this app will be sticking around. They are looking at a vended solution that may or may not eventually replace it.

The build is failing with the following messages (user name is redacted as ):

Severity    Code    Description Project File    Line    Suppression State
Error       Error in C:\Users\<me>\.nuget\packages\xamarin.androidx.lifecycle.common\2.5.1.1\buildTransitive\monoandroid12.0\..\..\jar\androidx.lifecycle.lifecycle-common.jar:androidx/lifecycle/DefaultLifecycleObserver.class:
Type androidx.lifecycle.DefaultLifecycleObserver is defined multiple times: C:\Users\<me>\.nuget\packages\xamarin.androidx.lifecycle.common\2.5.1.1\buildTransitive\monoandroid12.0\..\..\jar\androidx.lifecycle.lifecycle-common.jar:androidx/lifecycle/DefaultLifecycleObserver.class, C:\Users\<me>\.nuget\packages\xamarin.androidx.lifecycle.common.java8\2.3.1.3\buildTransitive\monoandroid90\..\..\jar\androidx.lifecycle.lifecycle-common-java8.jar:androidx/lifecycle/DefaultLifecycleObserver.class
Compilation failed
java.lang.RuntimeException: com.android.tools.r8.CompilationFailedException: Compilation failed to complete, origin: C:\Users\<me>\.nuget\packages\xamarin.androidx.lifecycle.common\2.5.1.1\buildTransitive\monoandroid12.0\..\..\jar\androidx.lifecycle.lifecycle-common.jar
androidx/lifecycle/DefaultLifecycleObserver.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\<me>\.nuget\packages\xamarin.androidx.lifecycle.common\2.5.1.1\buildTransitive\monoandroid12.0\..\..\jar\androidx.lifecycle.lifecycle-common.jar:androidx/lifecycle/DefaultLifecycleObserver.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.DefaultLifecycleObserver is defined multiple times: C:\Users\<me>\.nuget\packages\xamarin.androidx.lifecycle.common\2.5.1.1\buildTransitive\monoandroid12.0\..\..\jar\androidx.lifecycle.lifecycle-common.jar:androidx/lifecycle/DefaultLifecycleObserver.class, C:\Users\<me>\.nuget\packages\xamarin.androidx.lifecycle.common.java8\2.3.1.3\buildTransitive\monoandroid90\..\..\jar\androidx.lifecycle.lifecycle-common-java8.jar:androidx/lifecycle/DefaultLifecycleObserver.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  mobile.Droid            

I would thought to downgrade the urban airship libraries however doing so would cause problems involving the inclusion of bitcode with the iOS port which Apple would reject in a App submission. So a urban airship downgrade is not an real option. The other option was trying to maintain two separate main branches for the two platforms: One with the newer version that Apple requires and the one with the older version that was okay for Android. I did this for now and it worked to get it out the door but this is not ideal and I would like to be able to get around the class file conflict.

0

There are 0 best solutions below