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:
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
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
The next thing we need to do is create a sym link 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_v188.8.131.52_Linux-x86_64_master_878ba261-Debug.tar.bz2
tar xjf ./xamarin.android-oss_v184.108.40.206_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"
Configure SDK and NDK paths in Rider settings
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, you need to update the import directive at the end of the project file from this:
<Import Project=”$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets” />
You should now be able to build and deploy your project to a virtual device on Linux.
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: