Search code examples
androidxamarinxamarin.androidvisual-studio-2019.net-standard

Multi-platform development: use recent Visual Studio with older version of Android


[update] I finally was able to deploy our app on 4.2 using the latest toolchain. I get an error. See below after the original text.

We are looking for a long term solution to keep using recent version of Visual Studio (2019 at the time of this post) while keeping developping for old Android platforms (prior to 4.4).

Xamarin@Microsoft dropped support for Android previous to 4.4 in the Xamarin.Android release 9.2, but we cannot drop the support for our product. Until now we keep using VS2017 for our specific android development, but the gap between VS2019 and VS2017 development environment is increasing and this is adding an increasing overhead on our day-to-day development.

Our projects are developped using a mostly common code base for a software deployed on PC, but part of this code is also part of an Android application that can run on specific devices. For PC development which is our main activity, we want as much as possible to be able to code using the latest .NET standard and latest tools.

The Android version is an industrial software very specific to the hardware it is used on, and we cannot expect the Android OS to be updated, so we are stuck with a minimal Android version support of 4.2.2.

I already searched on SO and other forums, but didn't find any "good" long-term solution. For information here are some of the good information I found related to this topic:

https://learn.microsoft.com/en-us/xamarin/android/release-notes/9/9.2

https://learn.microsoft.com/en-us/xamarin/android/app-fundamentals/android-api-levels?tabs=windows

Which .Net Standard version supports which Android versions?

https://github.com/xamarin/xamarin-android/blob/master/Documentation/guides/messages/xa4216.md

https://learn.microsoft.com/en-us/dotnet/standard/net-standard

Currently I think what we can do is:

1) Mainly use .NET standard libraries for the common parts of our code

2) Having very few assemblies directly using Xamarin.Android, typically only for the UI part.

Note that this is close to what we are already doing now (except that we could port more of our assemblies to .NET Standard I think).

However since we target API level 4.4 and use the application on 4.2, we may call some APIs that are not supported in 4.2, or even worse, APIs that are supported but buggy because the new Xamarin/Mono runtime does not support old Android versions. This is especially true since there is the warning XA4216: even if we can deploy and run on an older android because the manifest allows it, we cannot ensure that the OS provides all the necessary features used by the mono runtime. At the moment the warning XA4216 is for version 4.0.3, but we see the day coming when we update VS2019 and get this warning for Android 4.2.

So is there a better solution than:

1) Keep the old VS2017/old Xamarin.Android build environment and block our day-to-day productivity to keep ensuring full compatibility with Android 4.2

2) Update our build and development environment fully to VS2019 with latest Xamarin and pray that the implementation is not bugged on older OS.

I would like to be able to go with 2 and have some insurance that everything will work fine, without having to retest the whole application each time there is an update of visual studio. What do you think? To ensure application stability, are we stuck with the old build system (VS2017 + old Xamarin.Android), or is it a "safe" risk to upgrade to VS2019 with latest Xamarin?

Thanks in advance for any good advice on this topic.

PS: I pushed with solution 2: "Update our build and development environment fully to VS2019 with latest Xamarin and pray that the implementation is not bugged on older OS." to do the test locally on my PC at first. After making necessary changes in our app so that it builds with VS2019 & latest Xamarin, I deployed to test on our Android 4.2.2 device (took me 1 whole day to fix the build errors...). I get the following error and app freezes: W/libc ( 9196): protoent* getprotobyname(char const*)(3) is not implemented on Android.

Maybe praying was not enough... any ideas?


Solution

  • Go with option 2 & update your build and development environment fully to VS2019 with latest Xamarin! The implementation should not bug any older OS.

    Even if it does add bugs, just test your code in QA. As for production, you can place good crash analytics on your app, and you ll be able to catch, report and fix any bugs.

    For the most part, on Android the number of users using below Android 4.4 is less than 0.001% of all users. At that point, it makes more sense to implement Accessibility in your app, since that affects 1000x more users.