Xamarin.Android on Linux

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:

I’m running KDE NEON based upon Ubuntu 18.04, which you can download from here. For help on setting up KDE NEON, see here.

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

sudo reboot

Next install Android Studio by downloading from here, extracting the archive, then running bin/studio.sh

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

Next install Mono as per the instructions here, and .NET Core as per here.

Update your .bashrc (found in your home folder), it should look something like this:

bash

Note: I had installed Android SDK to the default folder: $HOME/Android/Sdk

The next thing we need to do is create a sym link to the Android Emulator:

cd ~/Android/Sdk/tools

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

Install Xamarin.Android

Download a stable build from here.

I used: xamarin.android-oss_v9.1.199.8_Linux-x86_64_master_878ba261-Debug.tar.bz2

Extract it:

tar xjf ./xamarin.android-oss_v9.1.199.8_Linux-x86_64_master_878ba261-Debug.tar.bz2

Go to the unpacked dir:

cd ./xamarin.android-oss_v9.1.199.8_Linux-x86_64_master_878ba261-Debug

Make dirs:

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"

Make Symlinks:

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"

Configure SDK and NDK paths in Rider settings

Go to “File | Settings | Build, Execution, Deployment | Xamarin” and set “Android SDK location” and “Android NDK location”.

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:

<AndroidSupportedAbis>arm64-v8a;armeabi-v7a;x86;x86_64</AndroidSupportedAbis>

If you are using an existing project, you need to update the import directive at the end of the project file from this:

<Import Project=”$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets” />

To this:

<Import Project=”$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets”/>

You should now be able to build and deploy your project to a virtual device on Linux.

Conclusion

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.

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s