Old MVVMCross Xamarin solutions & the looming Android 10 Deadline
November 2 is coming close, be proactive to avoid a meltdown
Using cross platform frameworks like Xamarin has a lot of pros, in terms of the shorter learning curve and time of development. But changes needed due to unforeseen change in the native iOS & Android SDK’s is one of the disadvantages, as you will see in this article.
You must have read about the important changes to the Android Play Store requirements, from an article just published by Microsoft. It’s based on the deadline outlined by Android and summarized in this image:
The Google Play Store requirements state that, after November 2nd 2020 all app updates to Android apps will need to target the Android 10 (Q API Level 29) framework.
Fix for most Xamarin Apps
For most Xamarin and Xamarin.Forms apps, this is an easy 4-step fix:
- Open your Xamarin Solution (SLN) file in Microsoft Visual Studio, and double tap on your
Droidproject to open the Project Options
- Select the General Build options in the menu
- Change the Target Framework to Android 10 or newer
- Press OK, and you are done!
Why isn’t it that easy for MVVMCross?
If you are using an “MVVM framework” library (nuget package) like MVVMCross, you might have a lot of work ahead of you. These libraries are heavily tied in with the code of Xamarin Native solutions, and are used mainly to simplify navigation and code sharing, years before Xamarin.Forms became a lot more stable. So what’s the issue? As detailed on StackOverflow, due to changes in the Android SDK unforeseen by the MVVMCross framework, these apps cannot simply target the Android 10 framework. Your app will crash on load, unless you update to the MVVMCross version 6.4.1 libraries.
Updating Nuget packages is generally pretty easy, isn’t it? Well, the fix is not that easy because the updated versions of these MVVM framework libraries do not support the >5 yr old target framework of your “Core” projects, which probably use .NET Portable PCL 4.5 — Profile111. Tomasz, maintainer of the library, pointed out that there are potential workarounds like rolling your own
MvxLayoutInflater code or perhaps just stop using binding inflation with MvvmCross, and do all your bindings in code behind like on iOS, but I haven’t tried those yet.
So how do I update?
Theoretically, these are the steps you should follow to update your library version:
- You must first update your Core PCL project target framework to .NET Standard 2.0. There are several articles talking about this.
- Once you change that, now all your 3rd party libraries will require updates to a version that can support the newer Core target framework.
- You will have a lot of errors due to years of changes in those libraries (could be greater than 2000).
- Once you resolve 90% of those errors with simple fixes, a lot of changes will be needed to be made in all projects because the Setup of MVVMCross is a lot different from before.
My recommendation though is not to do try updating your library version! From my trials, I learned that the easiest way to update library versions is to take the latest working sample provided by MVVMCross with the newest target framework and libraries, and just make replacements to it, replacing pages piece by piece. As pointed above, perhaps try the potential workaround mentioned by Tomasz.
Why do I know about this?
Last year, I spent some of my free time trying to do the migration for an app during my free time as a challenge, following the tutorials & advice I received online, and picking brains of Xamarin consultants leading to a roadblock and a lot of realizations. For an app I just inherited, a major consulting company spent several months with the Xamarin apps doing the MVVMCross framework “migration”, and we are still fixing bugs created.
Is the migration going to make the app last for a while?
The migration isn’t all unfortunately. The other change made around the end of 2018 was that Android changed all its native libraries to “AndroidX”. From my conversations with the creators of MVVMCross, there is only an unofficial version of the library that supports AndroidX, but it’s workable. You don’t need to make this change for now, but with the soon to come MVVMCross version 7 libraries, you can keep publishing updates to your Xamarin MVVMCross Android apps for the foreseeable future.
MVVMCross is awesome!
The app I recently inherited, used MVVMCross with the 2013 version of the library and was pretty stable. The company only decided to migrate to the latest version, because of this Android 10 requirement. Taking that into consideration and despite this issue, I highly commend the framework creators and contributors for a fantastic library. Don’t forget to share this with your friends, as they may be unaware of this looming deadline. Please let me know your thoughts on Twitter or comment here.