Wednesday 25 October 2017

Xamarin cross platform apps for phones, etc.

I am starting to develop an app to run on phones and tablets, and, as I am familiar with C#, I decided to try Xamarin.

 It is an excellent environment, but full of pitfalls for the unwary.

 I installed Xamarin as part of Visual Studio 2017 Community Edition (which is free).

Unfortunately creating a new Xamarin project leaves you with a pile of NuGet packages, many of which are out of date, and some of which are installed in multiple versions.

Attempting to run the automatic update on all of them results in a cryptic error message.

You are trying to install this package into a project that targets 'MonoAndroid,Version=v7.1', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author. 

It appears that the versions of the Android NuGet packages you have to use depend on the version of the Android SDK you are targeting. Plus, as supplied, VS 2017 does not include an Android SDK which matches the latest NuGet packages.

There are 2 answers.


Upgrade your Visual Studio to the latest version, then go into Tools/Android/SDK Manager and update everything. Exit (it has probably updated itself) and re-enter. Repeat until all is up to date. Then make sure you have downloaded the latest SDK Platform. (You need to have all the SDK platforms between your Minimum Android Version and your Target Android Version, apparently.) Finally, adjust your Target Android Platform in your Android project properties, Application and Android Manifest tags, to the latest version. I understand it is best to select a specific version, rather than "Use latest".


Find the version of the SDK you are targeting, and upgrade all the Android packages individually by hand to the same major version number.