Unfortunately Xamarin does not really properly support Linux. The following steps allowed me to set up a Xamarin development environment and test the app on Android (not iOS).
- Download and extract JetBrains Rider, and move it to a useful location (e.g.
$HOME/opt/
). (Note: JetBrains offers free licenses for those with university email addresses.) - Install the .NET Core SDK.
- Install the Mono SDK.
- Install the JDK.
- Download and install Android Studio, and run through the first-time use setup to download and install the Android Emulator and SDKs.
- In the Android SDK Manager, ensure you have installed Android 9.0, 10.0, and 11.0, as well as the NDK (visible under "SDK Tools").
- In the Xamarin DevOps pipelines, find the most recent successful Linux build (two ticks) and click it.
- Under "Linux", click "3 artifacts".
- Hover over "Installers - Linux", click the three dots on the right, and click "Download artifacts".
- Extract the downloaded package, navigate to the directory, and extract the
tar.bz2
archive. (Note: the version I tested isxamarin.android-oss-v11.2.99.0_Linux-x86_64_5634_2488bf7d-Release
.) - In the archive, run the following commands:
sudo mkdir /usr/lib/xamarin.android
sudo mkdir /usr/lib/mono/xbuild/Xamarin/
sudo cp -a "bin/Release/lib/xamarin.android/." "/usr/lib/xamarin.android/"
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"
- Create some symlinks to support JetBrains Rider:
cd $HOME
mkdir Library
cd Library
ln -s ../Android .
cd Android
ln -s Sdk sdk
- Open JetBrains Rider, and click Configure -> Settings (in the bottom-left).
- Click "Android" in the menu, and set the paths accordingly. For example, I have:
- Android SDK Location:
/home/eleanor/Android/Sdk
- Android NDK Location:
/home/eleanor/Android/Sdk/ndk
- Java Development Kit Location:
/lib/jvm/default
- Creating a new Xamarin Application solution (called
App1
in this example), as follows:
- "New -> Application -> Xamarin Application"
- Select an up-to-date Android API (29 or 30)
- run the following commands in the JetBrains Rider terminal:
cd App1/App1.Android/Resources/
ln -s Resource.designer.cs Resource.Designer.cs
- You should now be able to build and run the app on the Android Emulator!
Make sure the target is set to App1.Android - iOS won't build on Linux. (This is a small drop-down menu near the green play button for building.)
If you get an error " Xamarin.Android.Tooling.targets(64, 5): [XA5300] The Android SDK directory could not be found. Check that the Android SDK Manager in Visual Studio shows a valid installation. To use a custom SDK path for a command line build, set the 'AndroidSdkDirectory' MSBuild property to the custom path.", go to "Build, Execution, Deployment" -> Android -> "SDK Components" and check the Android SDK location. Even if it seems correct, click "edit" and, when prompted, agree to update new components.