Thanks to the awesome guys at JetBrains and their Project Rider IDE, it’s now possible (unofficially) to develop Xamarin.Android apps on Linux.
This is a basic project created with Project Rider and running on the emulator:
Once I had a basic application up and running, I tried an application I’ve had in the store for a while (Temperament). It worked perfectly:
Note: Project Rider and Xamarin.Android is still a work in progress, so things change from time to time. I’ve updated this document as per my last successful install on Kde Neon and Ubuntu 19.04. There’s an Updates section at the end as a kind of history of the changes. If you get stuck, take a look at that section and some of the comments. These instructions are for Ubuntu 18.04 based distributions, for Ubuntu 19.04 there’s a few changes, please see here.
Install Essential Libraries
sudo apt-get install curl lzip lunzip plzip build-essential cmake automake autoconf libc6-i386 libncurses5:i386 libstdc++6:i386 lib32z1 libc6:i386 libbz2-1.0:i386 uudeview apt-transport-https
Setup Android Studio
Before installing Android Studio, starting with Ubuntu 18.04 you need to install qemu-kvm. Enter these commands:
sudo apt install qemu-kvm
sudo adduser $USER kvm
Next install Android Studio by downloading from here, extracting the archive, then running bin/studio.sh from the newly created android-studio folder.
Once Android Studio is up and running, test you can create a simple Android project and deploy to a virtual device (I created a Nexus 5×28 x86_64 device).
Now install SDK 28 and the NDK bundle via Android Studio.
Install Mono and .Net Core
Update your .bashrc (found in your home folder), it should look something like this:
Note: I had installed Android SDK to the default folder: $HOME/Android/Sdk
Update: Creating a symlink (see the following commands) was not required on my latest install, I advise you skip it. You can always do it later if you have a problem starting an emulator.
The next thing we need to do is create a symlink to the Android Emulator:
ln -s ../emulator/emulator emulator-x86
Install Oracle JDK
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer
Download a stable build from here.
I used: xamarin.android-oss_v18.104.22.168_Linux-x86_64_master_878ba261-Debug.tar.bz2
Update: The official Xamarin for Linux builds have been failing for over a month. Use the last successful build, you can find artifacts for the last successful build here.
tar xjf ./xamarin.android-oss_v22.214.171.124_Linux-x86_64_master_878ba261-Debug.tar.bz2
Go to the unpacked dir:
sudo mkdir "/usr/lib/xamarin.android" sudo mkdir "/usr/lib/mono/xbuild/Xamarin/"
Copy dir from extracted files:
sudo cp -a "bin/Debug/lib/xamarin.android/." "/usr/lib/xamarin.android/"
Delete dirs for next step:
rm -rf "/usr/lib/mono/xbuild/Xamarin/Android" rm -rf "/usr/lib/mono/xbuild-frameworks/MonoAndroid"
sudo ln -s "/usr/lib/xamarin.android/xbuild/Xamarin/Android/" "/usr/lib/mono/xbuild/Xamarin/Android" sudo ln -s "/usr/lib/xamarin.android/xbuild-frameworks/MonoAndroid/" "/usr/lib/mono/xbuild-frameworks/MonoAndroid"
As mentioned in the updates section below, you need to replace an assembly. Download this nuget package, unzip it, and then copy the file System.Reflection.Metadata.dll from the lib/netstandard2.0 folder over the file found in /usr/lib/mono/msbuild/15.0/bin/
Configure SDK and NDK paths in Rider settings
Update: In the latest version I just created a new Xamarin.Android project and the template prompted me to click a button to set up these paths.
Go to “File | Settings | Build, Execution, Deployment | Android” and set “Android SDK Location”, “Android NDK Location”, and “Java Development Kit Location” . For me, the locations are:
Update your Project File
You can now create a new Xamarin.Android project.
Whether you are creating a new project, or using an existing one, you need to update your project file. Open the .csproj file in your favourite editor, find this section:
<PropertyGroup Condition=” ‘$(Configuration)|$(Platform)’ == ‘Debug|AnyCPU’ “>
And add this setting:
If you are using an existing project and you have the following import directive at the end of the project file:
<Import Project=”$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets” />
Change it to this:
You should now be able to build and deploy your project to a virtual device on Linux.
Note: if you copy and paste, ensure the quotes are correct or you’ll get an error.
Strings.xml should be strings.xml
If you create a new project and get an error that a string resource can’t be found, rename the file Strings.xml in the file system to strings.xml.
I’d like to say a big thank you to the JetBrains team for this blog, and to Andreas Go for his help with getting the project file right. Project Rider is shaping up to be an awesome IDE.
Recently people have been reporting build issues, thanks to Abdelrahman here is a fix:
I was having the same issue as @JENS ECKERVOGT, after some researching about the subject i found out they changed from the msbuild built-in System.Reflection.Metadata to the one that comes with corefx project because it’s much faster.
so i searched nuget for System.Reflection.Metadata (https://www.nuget.org/packages/System.Reflection.Metadata/) downloaded the package and opened it in archive manager copying the dll that’s in netstandard 2.0 to msbuild directory and also did the same with (https://www.nuget.org/packages/System.Collections.Immutable/) and every thing works fine now
I’ve just been through a complete re-install, all of the above instructions worked fine (I needed to use Abdelrahman’s fix mentioned above but only for System.Reflection.Metadata). The location of the msbuild folder is:
For this install, I used this Xamarin build:
I had two minor issues:
Firstly, the settings (see Configure SDK and NDK paths in Rider settings section) has changed from:
File | Settings | Build, Execution, Deployment | Xamarin
File | Settings | Build, Execution, Deployment | Android
And you will need to enter the jdk location too, I specified:
The article has been updated accordingly.
Secondly, if you copy and paste the project file changes mentioned above (see the Update your Project File section) to an existing .csproj file, make sure the double quotes are correct after you paste the specified text, or your project won’t load.
This is a second application I just managed to run in Xamarin.Android on Linux following my latest install. I wrote this a few years ago and it is using a background service for playing an audio playlist. Everything is working as expected: