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.

 

 

11 thoughts on “Xamarin.Android on Linux

  1. I Can’t get it to work.
    I followed all your Steps however I can’t build a new Project.

    AndroidManifest.xml(6): [APT0000] resource string/app_name (aka Template.Template:string/app_name) not found.
    AndroidManifest.xml(7): [APT0000] resource string/app_name (aka Template.Template:string/app_name) not found.
    Xamarin.Android.Common.targets(2434, 3): [APT0000] failed processing manifest.

    Like

    1. Hi Simon, I’m too busy at the moment to investigate your issues, but in the meantime, can you check the entry in the manifest matches your resource name, i.e. string/app_name should probably be strings/app_name?

      Like

      1. Hi Velocity 🙂
        I can’t really explain it but it suddenly started working for me…

        I first thought there was a problem with the xamarin build.
        As Consequence I did download the build again, reinstalled libzip4.
        While it still didn’t work I tried to build a HelloWorld sample without rider, just using the xabuild…

        After that rider suddenly recognizes everything to be fine and I can now Build and Run perfectly fine..

        Maybe I should add something..
        From the template rider creates a strings.xml in the ResourcesFolder, however it References a “missing” Strings.xml (CaseSensitivity!!), so you either have to check the Dependencies or simply rename this file.

        Liked by 1 person

      2. Hey @Simon and @CSVelocity,
        Yeah you are right,

        I have tried to fix but I have sometimes error why does Xabuild won’t build cause it has sometimes assemblies not found like this

        How do you have not problem but for me not fixed. How do you have success? PLEASE TELL ME! I am very disappointed. Because I really miss to develop with Xamarin.Android on Linux and Rider. – Because I don’t like Windows 10 because Windows 10 failed major update into default desktop ( it seems after installation of Windows 10 ) since September/October 2018. I stopped work with Windows 10. I am working on Ubuntu. Why do idiots not support for MonoDevelop. That is why I am very disappointed and I don’t understand how does MonoGame Team work Android project for MonoDevelop. I feel like they lie me. Since 2 or 3 weeks later I found Rider and I have big problem with Xamarin.Android and Rider because it seems like string.xml and sometimes assemblies not found. I have already compiled Xamarin.Android from Github and compiled on Ubuntu 18.04 and It works fine ok. But Rider and xabuild won’t compile because I have problem with not found assemblies. How do I find?
        in /usr/lib/mono/4.5 or /usr/lib/mono/xbuild.frameworks or I want find for current assemblies.

        Like

      3. Hey Jens,

        well I can only take a guess but it looks like you’re missing some mono packages.

        Have you tried reinstalling mono ??
        sudo apt-get install –reinstall mono-complete

        Like

  2. I am very disappointed – Because it looks shit because Rider shows only latest Android version I want use old version of Android 8.1 ( Oreo )

    Why does Rider not compile successful ? =(

    Because I have already tried downloading Xamarin Android from github and I compiled successful. copy to /usr/lib/mono than i open Rider and create Xamarin Android App and it seems like shit always error error error error error….

    I have tried 5 or 6 times = NO SUCCESS.

    How did you get success? PLEASE SHOW ME VIDEO WITH SUBTITLE I want understand.

    Thanks

    Like

    1. Hi Jens, sorry to hear it is not working for you. I documented the steps I took to do two successful installs. I’ve been super busy lately, but will do another install soon and if necessary I’ll update the blog accordingly. Regarding versions, I just use what Microsoft makes available via their Jenkins builds.

      Like

      1. Thanks for your feedback Simon, glad you got it working. Hopefully Rider will evolve to be something like Android Studio for Xamarin, it’s awesome coding C# in Linux 🙂

        Like

  3. @Jens

    Hi Jens, sorry to hear of your troubles again, must be very frustrating.

    Are you able to create an Android Studio project and run it in an emulator? Can you create a mono project in Project Rider and run it successfully? If not, perhaps you’ll need to try a fresh install of Ubuntu 18.04 and follow the steps in the post exactly? For example, I don’t compile Xamarin.Android from Github.

    If you do try a fresh install, you’ll need to install packages like buildessential, and any libraries Android Studio needs to work correctly on Ubuntu. Make sure Android Studio and Project Rider is working BEFORE proceeding with the Xamarin.Android installation (Create a simple Android project, then create a Mono console project and run them).

    I’m really busy at the moment, but when I get a chance I’ll do another post soon specifically for Ubuntu 18.04 – from initial install up to and including Xamarin.Android for project Rider. In the meantime, I hope this helps.

    Like

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