dotnet / android-libraries

.NET for Android bindings for Google's libraries, such as AndroidX, GooglePlayServices, Firebase, and MLKit and their 3rd party dependency libraries.
MIT License
233 stars 50 forks source link

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

Closed XDarinor closed 1 year ago

XDarinor commented 1 year ago

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 commented 1 year ago

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

tbalcom commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

@XDarinor @tbalcom

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

moljac commented 1 year ago

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 commented 1 year ago

possibly related

https://github.com/xamarin/AndroidX/issues/634

https://github.com/xamarin/GooglePlayServicesComponents/issues/694

moljac commented 1 year ago

Workaround to test

https://github.com/xamarin/GooglePlayServicesComponents/issues/694#issuecomment-1516291763

tbalcom commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

@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 commented 1 year ago

@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 commented 1 year ago

@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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

@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 commented 1 year ago

@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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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

moljac commented 1 year ago

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 commented 1 year ago

@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 commented 1 year ago

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

moljac commented 1 year ago

@XDarinor @tbalcom @wfhm

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

Please report here.

Thanks

tbalcom commented 1 year ago

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 commented 1 year ago

@XDarinor @wfhm

Any news?

XDarinor commented 1 year ago

@XDarinor @wfhm

Any news?

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

moljac commented 1 year ago

@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 commented 1 year ago

@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 commented 1 year ago

@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 commented 1 year ago

Closing this issue

sphix0108 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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.

moljac commented 1 year ago

Duplicate

https://github.com/xamarin/GooglePlayServicesComponents/issues/775

Lsdenis commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

@tklempay Thanks for the feedback!

moljac commented 1 year ago

Duplicates:

https://github.com/xamarin/AndroidX/issues/717 https://github.com/xamarin/AndroidX/issues/742 https://github.com/xamarin/AndroidX/issues/747 https://github.com/xamarin/AndroidX/issues/749