AndroidX icon indicating copy to clipboard operation
AndroidX copied to clipboard

Xamarin.AndroidX.Lifecycle.LiveData dependecy error on updating to last version >>>> Building error

Open AngeloLazzari opened this issue 6 months ago • 16 comments

Android framework version

net9.0-android

Affected platform version

VS 17.4.6

Description

If we update this libraries to the last version

Image

we have a building error like this:

Document
  Name Value Type
$exception {System.MissingFieldException: Field not found: Microsoft.Maui.IPropertyMapper`2<Microsoft.Maui.IPicker, Microsoft.Maui.Handlers.IPickerHandler> Microsoft.Maui.Handlers.PickerHandler.Mapper Due to: Could not find field in class at Microsoft.Maui.Controls.Hosting.AppHostBuilderExtensions.RemapForControls(MauiAppBuilder builder) in //src/Controls/src/Core/Hosting/AppHostBuilderExtensions.cs:line 258 at Microsoft.Maui.Controls.Hosting.AppHostBuilderExtensions.SetupDefaults(MauiAppBuilder builder) in //src/Controls/src/Core/Hosting/AppHostBuilderExtensions.cs:line 202 at Microsoft.Maui.Controls.Hosting.AppHostBuilderExtensions.UseMauiPrimaryApp[App](MauiAppBuilder builder) in //src/Controls/src/Core/Hosting/AppHostBuilderExtensions.cs:line 43 at Microsoft.Maui.Controls.Hosting.AppHostBuilderExtensions.UseMauiApp[App](MauiAppBuilder builder) in //src/Controls/src/Xaml/Hosting/AppHostBuilderExtensions.cs:line 18 at LogikoApp.MauiProgram.CreateMauiApp() in C:\Users\lazza\LOGIKO-APP-2.0\logikoapp-maui\LogikoAppMaui\MauiProgram.cs:line 77 at LogikoApp.MainApplication.CreateMauiApp() in C:\Users\lazza\LOGIKO-APP-2.0\logikoapp-maui\LogikoAppMaui\Platforms\Android\MainApplication.cs:line 21 at Microsoft.Maui.MauiApplication.OnCreate() in /_/src/Core/src/Platform/Android/MauiApplication.cs:line 36 at Android.App.Application.n_OnCreate(IntPtr jnienv, IntPtr native__this) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net9.0/android-35/mcw/Android.App.Application.cs:line 1056 at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PP_V(_JniMarshal_PP_V callback, IntPtr jnienv, IntPtr klazz) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:line 22} System.MissingFieldException

and running the dotnet restore we get: Restore succeeded with 6 warning(s) in 1,5s C:\Users\lazza\LOGIKO-APP-2.0\logikoapp-maui\LogikoAppMaui\LogikoApp.csproj : warning NU1608: Detected package version outside of dependency constraint: Xamarin.AndroidX.Lifecycle.LiveData 2.8.7.3 requires Xamarin.AndroidX.Lifecycle.LiveData.Core.Ktx (>= 2.8.7.3 && < 2.8.8) but version Xamarin.AndroidX.Lifecycle.LiveData.Core.Ktx 2.9.1 was resolved. C:\Users\lazza\LOGIKO-APP-2.0\logikoapp-maui\LogikoAppMaui\LogikoApp.csproj : warning NU1608: Detected package version outside of dependency constraint: Xamarin.AndroidX.Lifecycle.LiveData 2.8.7.3 requires Xamarin.AndroidX.Lifecycle.LiveData.Core (>= 2.8.7.3 && < 2.8.8) but version Xamarin.AndroidX.Lifecycle.LiveData.Core 2.9.1 was resolved. C:\Users\lazza\LOGIKO-APP-2.0\logikoapp-maui\LogikoAppMaui\LogikoApp.csproj : warning NU1608: Detected package version outside of dependency constraint: Xamarin.AndroidX.Lifecycle.LiveData.Ktx 2.8.3.1 requires Xamarin.AndroidX.Lifecycle.LiveData.Core.Ktx (>= 2.8.3.1 && < 2.8.4) but version Xamarin.AndroidX.Lifecycle.LiveData.Core.Ktx 2.9.1 was resolved. C:\Users\lazza\LOGIKO-APP-2.0\logikoapp-maui\LogikoAppMaui\LogikoApp.csproj : warning NU1608: Detected package version outside of dependency constraint: Xamarin.AndroidX.Lifecycle.LiveData.Ktx 2.8.3.1 requires Xamarin.AndroidX.Lifecycle.LiveData (>= 2.8.3.1 && < 2.8.4) but version Xamarin.AndroidX.Lifecycle.LiveData 2.8.7.3 was resolved. C:\Users\lazza\LOGIKO-APP-2.0\logikoapp-maui\LogikoAppMaui\LogikoApp.csproj : warning NU1608: Detected package version outside of dependency constraint: Xamarin.AndroidX.Lifecycle.Common.Java8 2.8.7.2 requires Xamarin.AndroidX.Lifecycle.Common (>= 2.8.7.2 && < 2.8.8) but version Xamarin.AndroidX.Lifecycle.Common 2.9.1 was resolved. C:\Users\lazza\LOGIKO-APP-2.0\logikoapp-maui\LogikoAppMaui\LogikoApp.csproj : warning NU1701: Package 'ExifLib.PCL 1.0.1' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8, .NETFramework,Version=v4.8.1' instead of the project target framework 'net9.0-ios18.5'. This package may not be fully compatible with your project.

Build succeeded with 6 warning(s) in 1,6s PS C:\Users\lazza\LOGIKO-APP-2.0\logikoapp-maui>

if we downgrade to initial versions all is building correctly...

Relevant log output


AngeloLazzari avatar Jun 25 '25 07:06 AngeloLazzari

Can you share a .binlog of the build error? https://aka.ms/binlog

I don't understand why updating AndroidX NuGets would cause:

System.MissingFieldException: Field not found: Microsoft.Maui.IPropertyMapper`2<Microsoft.Maui.IPicker, Microsoft.Maui.Handlers.IPickerHandler> Microsoft.Maui.Handlers.PickerHandler.Mapper Due to: Could not find field in class at Microsoft.Maui.Controls.Hosting.AppHostBuilderExtensions.RemapForControls(MauiAppBuilder builder) in //src/Controls/src/Core/Hosting/AppHostBuilderExtensions.cs:line 258 at

On this line:

  • https://github.com/dotnet/maui/blob/b6d3543c12f0f2a1b5fc214f2ef1b23baf16ef9e/src/Controls/src/Core/Hosting/AppHostBuilderExtensions.cs#L258

jonathanpeppers avatar Jun 25 '25 21:06 jonathanpeppers

Hi, same problem here. I solved by downgrade Xamarin.AndroidX.Fragment and Xamarin.AndroidX.Fragment.Ktx to 1.8.6.2

gabrielrvd avatar Jun 27 '25 20:06 gabrielrvd

@gabrielrvd can you share a .binlog or link to a sample app?

jonathanpeppers avatar Jun 27 '25 20:06 jonathanpeppers

@gabrielrvd can you share a .binlog or link to a sample app?

HEllo, here is a sample app in the version that is compiling and running correctly (https://drive.google.com/file/d/17KbXx4RWL8R4nPVqewEYF9NroiU7gjLa/view?usp=sharing) , and the same sample app with the updated libraries and having the error... (https://drive.google.com/file/d/1ZaJAzKlOoiXdWboIpTmHnyAZj0C0K552/view?usp=sharing) ... I hope this helps ...

AngeloLazzari avatar Jun 30 '25 10:06 AngeloLazzari

Hi, same problem here. I solved by downgrade Xamarin.AndroidX.Fragment and Xamarin.AndroidX.Fragment.Ktx to 1.8.6.2

tks, fix here

andreptcosta avatar Jul 02 '25 21:07 andreptcosta

Hi, I installed the new version of Microsoft Visual Studio Community 2022 (64-bit) - Current Version 17.14.8, updated the dotnet worrkload.... updated the nugets... and the issue is still there....

My visual studio info Microsoft Visual Studio Community 2022 Version 17.14.8 VisualStudio.17.Release/17.14.8+36301.6 Microsoft .NET Framework Version 4.8.09032

Installed Version: Community

ASP.NET and Web Tools 17.14.114.53116 ASP.NET and Web Tools

Azure App Service Tools v3.0.0 17.14.114.53116 Azure App Service Tools v3.0.0

C# Tools 4.14.0-3.25326.11+bd4f2062291278e0df1e3fd3180c0c862495a3a7 C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

GitHub Copilot 17.14.827.52834 GitHub Copilot is an AI pair programmer that helps you write code faster and with less work.

Microsoft JVM Debugger 1.0 Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Mono Debugging for Visual Studio 17.14.11 (f3bc644800) Support for debugging Mono processes with Visual Studio

NuGet Package Manager 6.14.0 NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

Project System Tools 1.0 Tools for working with C#, VisualBasic, and F# projects.

Razor (ASP.NET Core) 17.14.3.2530601+3372435431977e91904a23ceb1eab689badc1bd9 Provides languages services for ASP.NET Core Razor.

TypeScript Tools 17.0.40502.2001 TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools 4.14.0-3.25326.11+bd4f2062291278e0df1e3fd3180c0c862495a3a7 Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools 17.14.0-beta.25230.7+c1a9d78ad4a474a716ccffb4367ed5151e3f7c9f Microsoft Visual F# Tools

Visual Studio IntelliCode 2.2 AI-assisted development for Visual Studio.

VisualStudio.DeviceLog 1.0 Information about my package

VisualStudio.Mac 1.0 Mac Extension for Visual Studio

VSPackage Extension 1.0 VSPackage Visual Studio Extension Detailed Info

Xamarin 17.14.268 (5ea1e283cd) Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer 17.14.3.0 (tags/main-61034a2(11307611)^0@61034a2622) Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin Templates 17.13.0 (6570271) Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.

Xamarin.Android SDK 13.2.2.0 (d17-5/45b0e14) Xamarin.Android Reference Assemblies and MSBuild support. Mono: d9a6e87 Java.Interop: xamarin/java.interop/d17-5@149d70fe SQLite: xamarin/sqlite/3.40.1@68c69d8 Xamarin.Android Tools: xamarin/xamarin-android-tools/d17-5@ca1552d

Xamarin.iOS and Xamarin.Mac SDK 16.4.0.23 (9defd91b3) Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.

AngeloLazzari avatar Jul 10 '25 10:07 AngeloLazzari

I don't see how updating Visual Studio or workloads would fix this.

Is this the same problem here?

  • https://github.com/dotnet/android-libraries/issues/1181#issuecomment-3053297891

We added typeforwarders in this package, that should fix this:

<PackageReference Include="Xamarin.AndroidX.SavedState" Version="1.3.0.1" />

jonathanpeppers avatar Jul 10 '25 13:07 jonathanpeppers

I don't see how updating Visual Studio or workloads would fix this.

Is this the same problem here?

We added typeforwarders in this package, that should fix this:

@jonathanpeppers , actually I don't know why updating nuget drove us in this situation, so, everything is coming to me is worth to try. IMO Visual Studio ecosystem is really delicated and fragile, most of the times we update anything something is going to broke... some times the fix is do a clean and all is runninng again, sometimes, like this time, not...

If I add that line to the project I have this error message:

Image

AngeloLazzari avatar Jul 10 '25 14:07 AngeloLazzari

You might need to add additional <PackageReference/> to solve the NU1605 warnings (or ignore them). You put the higher version that it's complaining about in the project.

jonathanpeppers avatar Jul 10 '25 14:07 jonathanpeppers

Same problem. None of the workarounds above seem to work for me though.

williambuchanan2 avatar Jul 15 '25 23:07 williambuchanan2

Is this the same problem here?

We added typeforwarders in this package, that should fix this:

adding this package fixed it for me, too.

MagicAndre1981 avatar Jul 16 '25 11:07 MagicAndre1981

Same issue here with latest versions: System.MissingFieldException: 'Field not found: Microsoft.Maui.IPropertyMapper`2<Microsoft.Maui.IPicker, Microsoft.Maui.Handlers.IPickerHandler> Microsoft.Maui.Handlers.PickerHandler.Mapper Due to: Could not find field in class'

tuk1976 avatar Jul 19 '25 10:07 tuk1976

add this Xamarin.AndroidX.SavedState nuget to your csproj file. For me it helped to solve this error.

MagicAndre1981 avatar Jul 19 '25 14:07 MagicAndre1981

Downgrading to Xamarin.AndroidX.Fragment.Ktx to 1.8.6.2 fixed the issue for me. Adding Xamarin.AndroidX.SavedState gave me a bunch of other dependency errors.

hammy33897 avatar Aug 03 '25 18:08 hammy33897

There seems to be a lot of issues with these libraries. I've had ongoing problems with them since I first installed them. I wonder if the problems change depending on what other libraries you have installed.

williambuchanan2 avatar Aug 03 '25 21:08 williambuchanan2

This works fine for me:

<ItemGroup Condition="'$(TargetFramework)' == 'net9.0-android'">
	<PackageReference Include="Xamarin.AndroidX.SavedState" Version="1.3.1" />
	<PackageReference Include="Xamarin.AndroidX.Fragment.Ktx" Version="1.8.8" />
</ItemGroup>

0xc3u avatar Aug 07 '25 09:08 0xc3u