Setting up Xamarin on GNU/Linux

Publication date: Oct 30, 2022

I had a university course this year which involved creating mobile applications.... ...using Xamarin.Forms. My school has a "great" track record of forcing Windows-only technologies down students' throats and this is no exception, of course(strictly speaking, it is, since macOS is supported). I always try to avoid using Windows where I possibly can, but setting up Xamarin.Android seemed like a nightmare under a non-Debian-based distro. Reading multiple tutorials led to me being able to install the required components but not able to compile any applications, so I had to do some research myself. Fortunately, I found the solution.

DISCLAIMER: This solution requires JetBrains Rider, a commercial proprietary IDE, but if you are in a situation similar to mine, you can acquire an education license for free.

The package management commands are intended for RHEL/Fedora, so you have to find the equvivalent for your distro's package manager. The other parts of this guide are not distro-specific.

Software installation

Mono

First, you need to install Mono. Most distributions have it packaged, but make sure the referenceassemblies-pcl package is in the repository. If it is not, you can try the official Mono repository if you are on RHEL or Fedora. Look for a package named like mono-complete or mono-devel. Under a Red Hat-based distro, for example, issue the following commands to install Mono(# means you need root privileges):

# rpm --import "https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF"
# curl https://download.mono-project.com/repo/centos8-vs.repo | tee /etc/yum.repos.d/mono-centos8-vs.repo
# dnf install mono-complete

JDK (NOT JRE)

You need to install a JDK, fortunately your distribution almost certainly packages a version of it. I recommend using Java 11 at the time of the publication of this article. Issue this(or a similar, depending on your distro) command to install JDK:

# dnf install java-11-openjdk-devel

JetBrains Rider

You are going to need JetBrains Rider. Install it from Flathub(NOT RECOMMENDED) or download it from the official website and follow the instructions.

Xamarin.Android

As a last step of the installation, we need to install Xamarin.Android. Finding a build from the GitHub page is not straightforward. Select the latest versioned tag: GitHub branch selectorScroll to downloads and click on the icon in the Ubuntu row:Xamarin.Android downloadsScroll down, and select "n artifacts" under the Linux option:Xamarin build selector Then select "installers-unsigned - Linux", click on the menu button, and select "Download artifacts". Extract the downloaded archive and open a terminal in that directory. Extract the tar.bz2 archive and copy its contents to the appropriate place:

$ tar xvf xamarin.android-oss-etc.tar.bz2
$ cd xamarin.android-ossetc/bin/Release
# mkdir -p /usr/lib/mono/xamarin-android/bin/
# cp -r lib/xamarin.android/* /usr/lib/mono
# cp -r bin/* /usr/lib/mono/xamarin-android/bin/

Xamarin.Android is installed.

Android SDK and environment setup

Start JetBrains Rider. Select Configure->Plugins and search for "Rider Xamarin Android Support", then install it.Rider plugin settingsRestart Rider, then select Build, Execution, Deployment->Android on the left side. Click on "Install new" under the SDK path selector and follow instructions. After it finished, select SDK Components under Android in the left side menu, switch to the SDK Tools tab and tick "NDK(Side by side)".Rider Android SDK componentsClick Save, wait for it to install, then return to the Build, Execution, Deployment->Android screen, select the SDK install directory, the NDK directory and the JDK directory. For reference, this is what it looks like on my Fedora setup:Rider Android configuration Take note of the first two paths. Open the .bash_profile, .zprofile or any other profile file depending on your login shell in your home directory and add:

export AndroidSdkPath="your/sdk/path"
export AndroidNdkPath="your/ndk/path"

Log out of your DE/WM and log back. You should be able to create new Xamarin projects in Rider and build existing ones.

Note when creating a new project

Since your filesystem will be case-sensitive, you will need to rename the "Resource/Resource.designer.cs" to "Resource.Designer.cs" in the Android project of your solution. After doing that, your project should compile.