xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.63k stars 1.87k forks source link

Bump MonoAndroid target to 13.0 #15718

Closed jfversluis closed 1 year ago

jfversluis commented 1 year ago

This builds Xamarin.Forms with the MonoAndroid 13.0 target. With this we can now use the latest Android(X) packages again and should be more prepared for future Android versions and targets.

However, this change is pretty significant as also a lot of the dependencies got a good bump in their version numbers. Please test your code carefully!

Fixes #15668 Fixes #15678 Fixes #15677 Fixes #15714

Also see https://github.com/xamarin/Essentials/pull/2087

jfversluis commented 1 year ago

/azp run

azure-pipelines[bot] commented 1 year ago
Azure Pipelines successfully started running 1 pipeline(s).
jfversluis commented 1 year ago

~Blocked until a dependency package is added to the proprietary feed~ Should be done

azure-pipelines[bot] commented 1 year ago
Azure Pipelines successfully started running 1 pipeline(s).
azure-pipelines[bot] commented 1 year ago
Azure Pipelines failed to run 1 pipeline(s).
MagicAndre1981 commented 1 year ago

there were a large number of AndroidX updates last week. Please also make sure this compiles

mos379 commented 1 year ago

@jfversluis Any chance of clearing the last failed checks?

jfversluis commented 1 year ago

I'm working on it!

jfversluis commented 1 year ago

/azp run

azure-pipelines[bot] commented 1 year ago
Azure Pipelines successfully started running 1 pipeline(s).
jfversluis commented 1 year ago

The build finally works hooray! Can someone that is watching this grab the NuGets from this build and try and see how that behaves on their Xamarin.Forms projects? @mos379 @MagicAndre1981 @kcrg @DouglasGiovanella

Instructions can be found here: https://github.com/xamarin/Xamarin.Forms/wiki/Preview-Packages#pull-requests-

AlleSchonWeg commented 1 year ago

My app builds in release mode with this fix. The error from this issue: https://github.com/xamarin/Xamarin.Forms/issues/15668 not occuring anymore.

MagicAndre1981 commented 1 year ago

My app builds in release mode with this fix. The error from this issue: #15668 not occuring anymore.

yes, the nugets 5.0.0.8488 work.

I only get NU1608 warnings about AndroidX nugets out of allowed version ranges. This should be fixed in a 2nd PR to not make this PR too large.

Warning NU1608  Detected package version outside of dependency constraint: Xamarin.Forms 5.0.0.8488 requires Xamarin.AndroidX.Lifecycle.LiveData (>= 2.3.1.1 && <= 2.5.1.1) but version Xamarin.AndroidX.Lifecycle.LiveData 2.6.1 was resolved.     
Warning NU1608  Detected package version outside of dependency constraint: Xamarin.Forms 5.0.0.8488 requires Xamarin.AndroidX.Browser (>= 1.3.0.6 && < 1.4.0) but version Xamarin.AndroidX.Browser 1.5.0 was resolved.  
Warning NU1608  Detected package version outside of dependency constraint: Xamarin.Forms 5.0.0.8488 requires Xamarin.AndroidX.Navigation.UI (>= 2.3.5.1 && < 2.4.0) but version Xamarin.AndroidX.Navigation.UI 2.5.3.1 was resolved.            
Warning NU1608  Detected package version outside of dependency constraint: Xamarin.Forms 5.0.0.8488 requires Xamarin.AndroidX.RecyclerView (>= 1.2.1.1 && < 1.3.0) but version Xamarin.AndroidX.RecyclerView 1.3.0 was resolved.    
Warning NU1608  Detected package version outside of dependency constraint: Xamarin.Forms 5.0.0.8488 requires Xamarin.Google.Android.Material (>= 1.4.0.2 && < 1.5.0) but version Xamarin.Google.Android.Material 1.8.0 was resolved.
Warning NU1608  Detected package version outside of dependency constraint: Xamarin.Forms 5.0.0.8488 requires Xamarin.AndroidX.Core (>= 1.6.0.1 && <= 1.9.0.1) but version Xamarin.AndroidX.Core 1.9.0.2 was resolved.   
jfversluis commented 1 year ago

I'd rather fix everything that has to do with this right now :)

Where do you see this warning? Is this on your own project? Then you'll have to update the dependencies on that project, not much I can do about that unless we drop the bottom of the range for these packages which I don't really would want to do.

I guess this needs some updating: https://github.com/xamarin/Xamarin.Forms/pull/15718/files#diff-a10b47d2a1fb6f9a0f879b70a6b268191496328089b0bd5776fcbd68759d59dbR18-R29

MagicAndre1981 commented 1 year ago

I see this in error list as warnings and I did manual androidx updates so I have higher versions compared to what XF defines in the nuspec.

Those warnings will show up from time to time when new androidx versions are released and the version is outside of the defined range.

jfversluis commented 1 year ago

@MagicAndre1981 pushed an update for that. If this is done building, could you give that another try?

MagicAndre1981 commented 1 year ago

could you give that another try?

now I only get 1 warning:

Warning NU1608 Detected package version outside of dependency constraint: Xamarin.Forms 5.0.0.8491 requires Xamarin.AndroidX.Lifecycle.LiveData (>= 2.3.1.1 && <= 2.5.1.2) but version Xamarin.AndroidX.Lifecycle.LiveData 2.6.1 was resolved.

You'll likely also need to check all other nuspec files (maps, dual screen which I don't use) and look that the referenced androidx version and versonges that they match.

Maybe also use the dependabot here that checks for new androidx lib updates in future to detect such issues earlier and be able to react faster. Can this bot also update the nuspecs?

kcrg commented 1 year ago

@jfversluis I can't compile my app in release mode (full linking, custom profiled AOT) using XF 5.0.0.8491. I don't override any AndroidX packages.

Build logs 6>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(649,5): error XALNK7000: Mono.Linker.MarkException: Error processing method: 'System.Void Xamarin.Forms.Platform.Android.ShellSearchView/ClipDrawableWrapper::.ctor(Android.Graphics.Drawables.Drawable)' in assembly: 'Xamarin.Forms.Platform.Android.dll' ---> Mono.Cecil.ResolutionException: Failed to resolve AndroidX.AppCompat.Graphics.Drawable.DrawableWrapperCompat 6>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(649,5): error XALNK7000: at Mono.Linker.Steps.MarkStep.HandleUnresolvedType(TypeReference reference) 6>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(649,5): error XALNK7000: at Mono.Linker.Steps.MarkStep.MarkType(TypeReference reference) 6>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(649,5): error XALNK7000: at MonoDroid.Tuner.MonoDroidMarkStep.MarkType(TypeReference reference) 6>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(649,5): error XALNK7000: at Mono.Linker.Steps.MarkStep.MarkType(TypeReference reference) 6>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(649,5): error XALNK7000: at MonoDroid.Tuner.MonoDroidMarkStep.MarkType(TypeReference reference) 6>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(649,5): error XALNK7000: at Mono.Linker.Steps.MarkStep.ProcessMethod(MethodDefinition method) 6>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(649,5): error XALNK7000: at Mono.Linker.Steps.MarkStep.ProcessQueue() 6>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(649,5): error XALNK7000: --- End of inner exception stack trace --- 6>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(649,5): error XALNK7000: at Mono.Linker.Steps.MarkStep.ProcessQueue() 6>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(649,5): error XALNK7000: at Mono.Linker.Steps.MarkStep.ProcessPrimaryQueue() 6>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(649,5): error XALNK7000: at Mono.Linker.Steps.MarkStep.Process() 6>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(649,5): error XALNK7000: at Mono.Linker.Steps.MarkStep.Process(LinkContext context) 6>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(649,5): error XALNK7000: at MonoDroid.Tuner.MonoDroidMarkStep.Process(LinkContext context) 6>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(649,5): error XALNK7000: at Mono.Linker.Pipeline.ProcessStep(LinkContext context, IStep step) 6>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(649,5): error XALNK7000: at Mono.Linker.Pipeline.Process(LinkContext context) 6>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(649,5): error XALNK7000: at MonoDroid.Tuner.Linker.Process(LinkerOptions options, ILogger logger, LinkContext& context) 6>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(649,5): error XALNK7000: at Xamarin.Android.Tasks.LinkAssemblies.Execute(DirectoryAssemblyResolver res) 6>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(649,5): error XALNK7000: at Xamarin.Android.Tasks.LinkAssemblies.RunTask() 6>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(649,5): error XALNK7000: at Microsoft.Android.Build.Tasks.AndroidTask.Execute() in /Users/runner/work/1/s/xamarin-android/external/xamarin-android-tools/src/Microsoft.Android.Build.BaseTasks/AndroidTask.cs:line 17 ========== Build: 5 succeeded, 1 failed, 5 up-to-date, 0 skipped ==========

Edit: I found workaround, just added Xamarin.AndroidX.AppCompat 1.6.1 to my android project. After that everything builds and works.

MagicAndre1981 commented 1 year ago

ok, so dependency id entries for Xamarin.AndroidX.AppCompat/Xamarin.AndroidX.AppCompatResources in Version 1.6.1 needs to be added. to nuspec

jfversluis commented 1 year ago

Maybe also use the dependabot here that checks for new androidx lib updates in future to detect such issues earlier and be able to react faster. Can this bot also update the nuspecs?

Appreciate the idea, but I don't think we want to do that. The reason we're so careful with these dependency versions is because in the past this has introduced breaking changes, that is why we limit the scope to a certain set of which we are sure that it will work with our version of Forms.

In this case, I will have to bump the versions as we're touching a lot now anyway, but I'm not super happy about it 😄 the closer we get to May 2024, when support ends, the more careful we want to be with breaking changes.

Updated the versions some more and also added that AppCompat version >= 1.6.0

MagicAndre1981 commented 1 year ago

can you configure the boot only generare drafts for AndroidX nugets and if build is green, simply close it without merging. Only when google breaks something and build fails check the PR, fix code/nuspecs and release a new XF update.

siddhant-maurya commented 1 year ago

I am using the latest available version 5.0.0.2578 and I am getting below error. Can someone please update how to fix it!

C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(649,5): error XALNK7000: Mono.Linker.MarkException: Error processing method: 'System.Void Xamarin.Forms.Platform.Android.ShellSearchView/ClipDrawableWrapper::.ctor(Android.Graphics.Drawables.Drawable)' in assembly: 'Xamarin.Forms.Platform.Android.dll' ---> Mono.Cecil.ResolutionException: Failed to resolve AndroidX.AppCompat.Graphics.Drawable.DrawableWrapper

jfversluis commented 1 year ago

@siddhant-maurya look a few comments up, that person had the same issue

siddhant-maurya commented 1 year ago

@jfversluis Thanks for the quick response. I tried adding Xamarin.AndroidX.AppCompat 1.6.1 but after many attempts I am still getting the same error.

mos379 commented 1 year ago

@siddhant-maurya you are using the wrong XF version. try 5.0.0.8491

siddhant-maurya commented 1 year ago

I am not able to find XF version 5.0.0.8491 in Nuget pkg manager or anywhere else can you please suggest how to get it. Iam using VS 2022 17.5.4

MagicAndre1981 commented 1 year ago

add this feed as nuget source: https://aka.ms/forms-prs/index.json to get the nugets for Pull Requests

siddhant-maurya commented 1 year ago

I have upgraded to XF version 5.0.0.8491 but now it's giving me some other errors - Any idea what is causing this error?

5>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1509,3): error XA4215: The Java typejavax.inject.Injectis generated by more than one managed type. Please change the [Register] attribute so that the same Java type is not emitted. 5>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1509,3): error XA4215:javax.inject.Injectgenerated by: Javax.Inject.IInject, Scanbot.Xamarin.SDK.Dependencies, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null 5>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1509,3): error XA4215:javax.inject.Injectgenerated by: JavaX.Inject.IInject, Xamarin.JavaX.Inject, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null 5>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1509,3): error XA4215: The Java typejavax.inject.Namedis generated by more than one managed type. Please change the [Register] attribute so that the same Java type is not emitted. 5>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1509,3): error XA4215:javax.inject.Namedgenerated by: Javax.Inject.INamed, Scanbot.Xamarin.SDK.Dependencies, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null 5>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1509,3): error XA4215:javax.inject.Namedgenerated by: JavaX.Inject.INamed, Xamarin.JavaX.Inject, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null 5>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1509,3): error XA4215: The Java typejavax.inject.Provideris generated by more than one managed type. Please change the [Register] attribute so that the same Java type is not emitted. 5>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1509,3): error XA4215:javax.inject.Providergenerated by: Javax.Inject.IProvider, Scanbot.Xamarin.SDK.Dependencies, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null 5>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1509,3): error XA4215:javax.inject.Providergenerated by: JavaX.Inject.IProvider, Xamarin.JavaX.Inject, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null 5>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1509,3): error XA4215: The Java typejavax.inject.Qualifieris generated by more than one managed type. Please change the [Register] attribute so that the same Java type is not emitted. 5>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1509,3): error XA4215:javax.inject.Qualifiergenerated by: Javax.Inject.IQualifier, Scanbot.Xamarin.SDK.Dependencies, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null 5>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1509,3): error XA4215:javax.inject.Qualifiergenerated by: JavaX.Inject.IQualifier, Xamarin.JavaX.Inject, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null 5>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1509,3): error XA4215: The Java typejavax.inject.Scopeis generated by more than one managed type. Please change the [Register] attribute so that the same Java type is not emitted. 5>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1509,3): error XA4215:javax.inject.Scopegenerated by: Javax.Inject.IScope, Scanbot.Xamarin.SDK.Dependencies, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null 5>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1509,3): error XA4215:javax.inject.Scopegenerated by: JavaX.Inject.IScope, Xamarin.JavaX.Inject, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null 5>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1509,3): error XA4215: The Java typejavax.inject.Singletonis generated by more than one managed type. Please change the [Register] attribute so that the same Java type is not emitted. 5>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1509,3): error XA4215:javax.inject.Singletongenerated by: Javax.Inject.ISingleton, Scanbot.Xamarin.SDK.Dependencies, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null 5>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1509,3): error XA4215:javax.inject.Singletongenerated by: JavaX.Inject.ISingleton, Xamarin.JavaX.Inject, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null

MagicAndre1981 commented 1 year ago

remove this Scanbot.Xamarin.SDK.Dependencies and only use official AndroidX libs from Xamarin team

siddhant-maurya commented 1 year ago

got it removed the Scanbot SDK and worked ! Thanks a lot :)

MagicAndre1981 commented 1 year ago

nice to hear this and build is green again 🥳 @jfversluis

jfversluis commented 1 year ago

Yeah it seems like LiveData 2.6.1 is causing issues, so I think I will go with this for now

MagicAndre1981 commented 1 year ago

ok, I tested 5.0.0.8503 and for me it works and I only get the now expected LiveData out of range warning

jfversluis commented 1 year ago

It's weird that it let's you install the latest version though because I limit it through the nuspec. Is that not enforced anymore? Did that change?

MagicAndre1981 commented 1 year ago

I don't configure that warnings are treated as errors, so this works.

MagicAndre1981 commented 1 year ago

I created a complete new app in VS2022 without any additional androidx references, updated to 5.0.0.8503 and see those warnings:

Warning NU1605  Detected package downgrade: Xamarin.AndroidX.CustomView from 1.1.0.14 to 1.1.0.7. Reference the package directly from the project to select a different version. 
 XFDemoApp.Android -> Xamarin.Forms 5.0.0.8503 -> Xamarin.AndroidX.AppCompat 1.6.0 -> Xamarin.AndroidX.Fragment 1.5.5 -> Xamarin.AndroidX.ViewPager 1.0.0.15 -> Xamarin.AndroidX.CustomView (>= 1.1.0.14) 
 XFDemoApp.Android -> Xamarin.Forms 5.0.0.8503 -> Xamarin.AndroidX.CustomView (>= 1.1.0.7 && < 1.2.0)   XFDemoApp.Android   
Warning NU1605  Detected package downgrade: Xamarin.AndroidX.Core from 1.9.0.1 to 1.6.0.1. Reference the package directly from the project to select a different version. 
 XFDemoApp.Android -> Xamarin.Forms 5.0.0.8503 -> Xamarin.AndroidX.AppCompat 1.6.0 -> Xamarin.AndroidX.Core (>= 1.9.0.1) 
 XFDemoApp.Android -> Xamarin.Forms 5.0.0.8503 -> Xamarin.AndroidX.Core (>= 1.6.0.1 && < 2.0.0)     
Warning NU1605  Detected package downgrade: Xamarin.AndroidX.CustomView from 1.1.0.14 to 1.1.0.7. Reference the package directly from the project to select a different version. 
 XFDemoApp.Android -> Xamarin.Forms 5.0.0.8503 -> Xamarin.AndroidX.AppCompat 1.6.0 -> Xamarin.AndroidX.DrawerLayout 1.1.1.10 -> Xamarin.AndroidX.CustomView (>= 1.1.0.14) 
 XFDemoApp.Android -> Xamarin.Forms 5.0.0.8503 -> Xamarin.AndroidX.CustomView (>= 1.1.0.7 && < 1.2.0)
jfversluis commented 1 year ago

Hm yeah I probably need to update the templates as well to use this new version directly. And maybe some blog post or something to explain what is going on here 😅

MagicAndre1981 commented 1 year ago

yes, this is a breaking change that should be tested and documented well.

A bit offtopic, maybe also retarget Essentials to 13.0 to match the new XF version.

cncb-gh commented 1 year ago

How does one get this before it makes its way to NuGet?

MagicAndre1981 commented 1 year ago

How does one get this before it makes its way to NuGet?

there are preview nugets packages on nuget.org

MitchBomcanhao commented 1 year ago

@jfversluis when are we to expect a release version that includes these changes? the deadline for app submissions is looming...

MitchBomcanhao commented 1 year ago

bump @jfversluis @jamesmontemagno

MitchBomcanhao commented 1 year ago

hello? @jfversluis @jamesmontemagno

MagicAndre1981 commented 1 year ago

I suspect it takes some time for 3rd party control vendors to update their libs as they also need to rebuild their controls for MAUI. Syncfusion is known to always target old XF / MAUI versions and I guess they may need some time to test their controls against new AndroidX libs.