Xamarin.CommunityToolkit Sample App Building on Windows
Since the Xamarin Community Toolkit has been out, there has already been a lot of love! Thank you for that! A good number of people wanted to try out the Xamarin.CommunityToolkit sample app that is in the repository, but on Windows it will give you a hard time actually building and running it. Here is a quick blog post with some things you might encounter and how to fix them.
Underneath you will find some different issues that you might encounter while trying to build the Xamarin Community Toolkit on your local machine on Windows. However, you might encounter multiple, so if you’ve fixed one and it still doesn’t work, see if the next issue is also in this post.
Your issue isn’t here? Please ping me through any way that is convenient to you, probably easiest is on Twitter, either public or slide into my DMs.
A Little Background Information on the Xamarin.CommunityToolkit Sample App #
Let’s start with a little background information. This will be a bit technical and I won’t explain everything in depth, but it should give you at least some terms to Google for if you want to know more :)
The Xamarin.CommunityToolkit is set up to be a multi-targeting project. This means; all code for all different platforms live in a single project. Depending on the target you select, a different path in that code is compiled. Right now we have a very rough cut: on Windows we won’t build macOS/iOS stuff and on macOS we won’t build UWP and WPF stuff.
For the sample app, we link the actual Toolkit source project. This means you’re also building that entire source. And that subsequently means that you will have all prerequisites for that installed. So, even if you want to build the Android sample app, which most of you want to do, you will still need the right UWP SDK version to be able to build the Xamarin.CommunityToolkit.dll.
Let’s have a look at what you can encounter while doing this.
“Fake” UWP Build Errors #
Some people reported to me that they will see many(!) errors when they try to build the Android app. These errors seem to originate from UWP, which is strange because they’re trying to build the Android app!
Fake UWP Errors example in Visual Studio Error List
Reason for that is explained above. So, let’s just see how we can fix this… That’s easy: just ignore it! 🤯
Let me explain. These errors come up due to an error or incompleteness (I don’t know which one) in the tooling. More specifically: the combination of Xamarin and the MSBuild.Sdk.Extras which handles the multi-targeting. You should be able to just ignore these errors. So, instead of building and seeing errors, just try to set the Android project as the startup project and hit run.
Does it work? Awesome! Enjoy!
It doesn’t work…? Then there is probably a real error somewhere in that big list of errors you’re facing. In that case you can do two things: parse the list of errors to see if you spot any, or install the current Version 16.9.0 Preview 3.0 of Visual Studio 2019. That has an update to fix the UWP/multi-targeting errors. In the latter case you will then only see the remaining “real” errors.
The Specified Language Targets For uap10.0.17763 is Missing #
This basically just means: you don’t have the right UWP SDK installed. You will need version 10.0.17763 installed on your machine.
Why do you need the UWP SDK? Read the above, it’s multi-targeting. Even if you just want to build Android, you will still need to build everything else too.
I’m writing UWP SDK, but it’s actually named Windows 10 SDK. You’ll need version 10.0.17763. If you don’t have it, you should be able to install it through the Visual Studio Installer. Click Modify on the installation that you’re using, then go to the Individual Components tab at the top and search for Windows SDK. Click the right version and install! You can see a sample in the screenshot below.
Install the Windows SDK 10.0.17763 version through the Visual Studio Installer
Error CS0012 The type ‘x’ is defined in an assembly that is not referenced. #
This error, later on it says something about UWP as well, is the same cause as the error right above this one. Check that you got the right Windows SDK version(s) installed and try again.
The error basically just means that the Toolkit is using a type that cannot be found. It can’t be found because that type is available in a Windows SDK that is not installed. Makes sense, right?
Failed To Generate Java Type For Class: Google.Android.Material.BottomNavigation.BottomNavigationView/IOnNavigationItemReselectedListenerImplementor due to MAX_PATH #
Your error might be a variation of the above, but the keyword here is: MAX_PATH. On Windows machine there is a maximum length to the file paths on your filesystem. Unfortunately, you can hit this pretty easily, especially with some of the generated types that Visual Studio will come up with in the Java parts of your app.
See the screenshot below. Where that red blob is (I removed some private names there) you can see the path and it’s pretty long. Whenever that happens, try to move (or clone the repo again) as close as you’re comfortable with to the root of your drive.
Visual Studio Error List showing the MAX_PATH error details
C:\xct or something like that. That should fix this problem.
Go Explore the Xamarin.CommunityToolkit Sample App #
That’s it, that’s all I have to offer for now. As mentioned, if there is an error you’re seeing that’s not on the list or you can’t get a solution to work, please let me know. I’m happy to have a look together and get it to run.
Also, if you need help getting started with contributing or anything Xamarin.CommunityToolkit, let me know! Here’s an introduction video that might be handy for you to review and while you’re there: please subscribe to my channel for more content.