Upgrading from Xamarin.Android to net7.0-android #14598
Replies: 4 comments 3 replies
-
@jonathanpeppers can probably explain the tech best. Short version is that Android libraries are largely compatible with .NET 6+ and don't require a recompilation like Xamarin.iOS libraries do.
NuGet.org - the light blues are not guaranteed. NuGet.org is guessing. So you have to try them to see if the package is indeed compatible. Our guidance for library developers is to explicitly add support for .NET 6+ TFMs. This will make them dark blue and provide that confidence to consumers of the packages. Yes there is an inheritance relationship.
Add the .NET 7+ TFM, recompile and repack. See @Sweekriti91 's comment here dotnet/docs-maui#289 (comment) I'll defer the rest of your questions to others. fyi @Redth @mattleibow |
Beta Was this translation helpful? Give feedback.
-
On porting a Xamarin.Forms/Xamarin.Android app to .NET 7:
We've kept However, it doesn't mean that everything will still work. Note that Xamarin.Forms projects are not officially supported in .NET 6+. When you have a Xamarin.Android class library, it was compiled against Xamarin/Mono's BCL. This is similar to migrating from .NET framework to .NET Core -- the BCL is different, so some random System.* classes may cause builds to fail or not function the same at runtime. For the best results, I would recommend moving to at least |
Beta Was this translation helpful? Give feedback.
-
Yes, you don't want to port a Xamarin.Forms app to .NET 6/7, you want to port it to .NET MAUI. Many of those things apply...
My article was more about non-Xamarin.Forms apps and migrating them up. For Libraries you can still multi-target both older Xamarin targets and new .NET targets. See what I do here for Xamarin.Essentials and .NET MAUI Essentials for the Android bits -> https://github.com/jamesmontemagno/InAppBillingPlugin/blob/master/src/Plugin.InAppBilling/Plugin.InAppBilling.csproj |
Beta Was this translation helpful? Give feedback.
-
Thank you for all the answers - this makes it clearer! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm currently evaluating how to upgrade existing apps built with Xamarin.Android (and Xamarin.Forms) to .NET 7. I found an article from @jamesmontemagno in the DevBlogs that was very interesting:
https://devblogs.microsoft.com/xamarin/upgrade-xamarin-ios-android-to-dotnet6-dotnet7/
The article also points to an interesting section in the Docs:
https://learn.microsoft.com/dotnet/maui/migration/
and especially:
https://learn.microsoft.com/dotnet/maui/migration/native-projects
I always thought that the build stuff used in Xamarin.Android was also used as base for the .NET 5/6/7 implementation for Android, and I think my experiments confirm this.
I have a few questions, though, and I think it's a good place here in the Discussions to ask and discuss and also ask other developers what your experiences are.
Note that this is not about converting a Forms app to .NET MAUI.
I just tried out if that path even works, so I created an empty "Android Application" project (not an "Android App (Xamarin)"), and it generates me a nice
net7.0-android
targeted app project. My next step was to create a "Mobile App (Xamarin.Forms)", which creates me the platform specific project(s) and anetstandard2.0
project with Forms code in it. I immediately throw away the platform specific projects, as I want to use thenet7.0-android
project for building. I have to copy over some code inMainActivity.cs
from the non-SDK-style Android project (e.g. deriving fromFormsAppCompatActivity
,Forms.Init
and loading the Forms app). To my surprise, everything compiles, links and deploys and I get a basic Forms app using .NET 7.Some questions already arise here:
netstandard2.0
- is this a good thing? Or would converting it tonet7.0
make sense? Or does it have to benet7.0-android
?Now I wanted to try upgrading actual apps of me (both personal and work projects) in order to get some experience. For that, I have to actually upgrade some projects with code and NuGet packages in it.
James writes in his blog article that some NuGet packages must be updated to work with the migrated
net7.0-android
targeted projects. Sometimes, when the original maintainer of a NuGet package is not available, I even might need to fork the project and do the changes (if any?) myself.Also, some time ago I saw that NuGet.org's packages page (e.g. here: https://www.nuget.org/packages/Xamarin.CommunityToolkit/) lists all supported
TargetFrameworks
(in the "Frameworks" tab). The blue target frameworks are directly supported ("Compatible target framework(s)"), and the light blue target frameworks are derived from them somehow ("Additional computed target framework(s)").net7.0-android
listed as Additional computed target framework? Does the package restore correctly and can be used in anet7.0-android
project?net7.0-android
. Does it work that way? If yes, can we see that mapping (logic) somewhere?MSBuild.Sdk.Extras
based projects?I have some projects where I wanted to put all code, platform specific and platform agnostic, in one project. I copied
Xamarin.Essentials
' approach and use theMSBuild.Sdk.Extras
SDK to do "poor-devs multi-targeting". I guess some NuGet package maintainers used the same approach to structure their packages.MSBuild.Sdk.Extras
isn't updated anymore and most probably not supported by Microsoft officially, I guess they should be converted to real SDK-style projects? Can I still targetMonoAndroid
there? My guess is no...I know this paragraph might better be an Issue, but maybe it plays a role in this discussion as well. My story continues with adding some NuGet packages, which most of them not aware of the new .NET 5/6/7 world, since they were created in the Xamarin.Forms era. After some of the NuGet packages are added, the NETSDK1136 error appears, saying I must target
net7.0-windows
as well. Is that an effect of the NuGet packages not supporting some target frameworks? The whole error line in Diagnostic verbosity is, btw:Thanks for reading through all of this! I'm sorry it's that long, but I can imagine that some developers have the same questions during their evaluation of how to migrate their apps!
Beta Was this translation helpful? Give feedback.
All reactions