Search code examples
maui.net-7.0maui-android

AndroidX.Work is not supported in maui with targeting .net 7


I'm trying to do run background tasks in Maui. previously the code worked with Xamarin forms in Android. But now it is failing and facing not exist errors with AndroidX. Work while trying with .NET MAUI with .NET 7. Please suggest any possibility to implement or any alternate ideas to do background tasks in Maui targeting .NET 7.

try to add this Xamarin.AndroidX.Work.Work.Runtime.Ktx but failed to add nuget. if we downgrade its targeting .net 6 only

Detected package downgrade: Xamarin.AndroidX.Lifecycle.LiveData from 2.6.2.2 to 2.5.1.1. Reference the package directly from the project to select a different version. 
 MyApp -> Xamarin.AndroidX.Work.Work.Runtime.Ktx 2.8.1.5 -> Xamarin.AndroidX.Work.Runtime 2.8.1.5 -> Xamarin.AndroidX.Lifecycle.LiveData (>= 2.6.2.2) 
MyApp-> Xamarin.AndroidX.Lifecycle.LiveData (>= 2.5.1.1)

Solution

  • First of all, this error is caused by Xamarin.AndroidX.Lifecycle.LiveData version 2.5.1.1 is referenced by the Maui .net 7.0 android sdk that can't be changed by nuget manager.

    So you can try to use the Xamarin.AndroidX.Work.Work.Runtime.Ktx's old version. Such as: Xamarin.AndroidX.Work.Work.Runtime.Ktx version 2.7.1.5. I have tried it and can be installed in my .net 7 project.

    In addtion, you can also try to update your project to .net 8.0. The .net 8.0 maui android sdk doesn't reference the Xamarin.AndroidX.Lifecycle.LiveData package, so you can install the Xamarin.AndroidX.Lifecycle.LiveData versoin 2.6.2.2 and the Xamarin.AndroidX.Work.Work.Runtime.Ktx version 2.8.1.5 at the same time in the .net 8.0.