First of all, a disclaimer: I'm a complete newbie when it comes to Android development, so take the information presented here with a pinch of salt. Nevertheless, as a complete newbie, I'm trying to compile a checklist of things needed to be able to develop Android software in F# on Windows. The information out there on the web is confusing and conflicting, hopefully this checklist will help. Note that the information is current for February 2020, so things will probably change in the future (I will try to update the checklist accordingly).
Also note that this checklist assumes you will be using Fabulous for your development, which is a functional Model-View-Update framework built on top of Xamarin.Forms. I'm not sure whether you can use it to develop apps with Xamarin.Android (a.k.a. Xamarin Native). Hopefully someone in the F# community will clear this up and I will update the post.
This checklist does not cover iOS since I don't have any Apple devices I could test the installation with.
Based on Microsoft's documentation, if you have an Intel processor, you should use Intel's HAXM for hardware acceleration "for the best experience on Windows". The trouble is that (at least in my case) the installation of HAXM fails, saying I have to disable Hyper-V Windows feature, which I need for other things (like running Docker). So I'm left with WHPX, which you enable by turning on Hyper-V and Windows Hypervisor Platform Windows features.
Developing in Visual Studio
If you plan to use Visual Studio 2019 for Android development, you need following things:
- F# Desktop Language Support - I installed it through the Visual Studio Installer.
- USB Device Connectivity - I installed it through the Visual Studio Installer.
- .NET Core Cross-platform development for Visual Studio 2019 - in addition to using the Visual Studio Installer, you can install it using Chocolatey:
choco install choco install visualstudio2019-workload-netcoretools -y
- Mobile development with .NET workload for Visual Studio 2019 - in addition to using the Visual Studio Installer, you can install it using Chocolatey:
choco install visualstudio2019-workload-netcrossplat -y
Do not use Visual Studio's F# Android project templates, they are obsolete and fail in all sorts of ways. I lost a lot of time figuring this out. Instead, use Fabulous templates (see section below).
Developing in JetBrains Rider
If you plan to use JetBrains Rider for Android development, you need to:
- Install JetBrains Android plugin for Xamarin Android plugin.
- Get Android SDK (if you have VS configured for Android use, you already have the SDK).
Since I have both VS and Rider installed, these may not be the only steps needed for Rider.
Developing in Visual Studio Code
Based on the comment made by Don Syme, you cannot run/deploy/debug Fabulous apps in VS Code.
Setting up a solution using Fabulous
The instructions were adapted from here:
- Open a command prompt window and install the template pack by entering:
dotnet new -i Fabulous.XamarinForms.Templates
- Navigate to a folder in the command prompt window where your new app can be created and enter:
dotnet new fabulous-xf-app -n <solution name> --iOS=false(replace
<solution name>) with the name of your new solution. Note that we disabled the generation of iOS project.
Do not update NuGet packages that come with the project template. I lost two hours trying to make this work and in the end I gave up - after running the update, Visual Studio reports an error and the build log contains a whole bunch of warning about missing references (which aren't really missing).
Alas, even without updating the NuGet packages, the build still reports
No way to resolve conflict between "mscorlib, Version=184.108.40.206, Culture=neutral, PublicKeyToken=b77a5c561934e089" and "mscorlib, Version=220.127.116.11, Culture=neutral, PublicKeyToken=7cec85d7bea7798e". Choosing "mscorlib, Version=18.104.22.168, Culture=neutral, PublicKeyToken=b77a5c561934e089" arbitrarily.
... but it builds (and runs) successfully. I tried to discover what is causing this warning and how to fix it, but so far I did not find anything.
Trying to build via dotnet build tool
My next goal was to be able to build the solution using the
dotnet build tool, but that was not successful:
warning NU1503: Skipping restore for project 'E:\src\test\Test.Android\Test.Android.fsproj'. The project file may be invalid or missing targets required for restore. [E:\src\test\Test.Android\Test.sln] error MSB4019: The imported project "C:\Program Files\dotnet\sdk\3.1.101\Xamarin\Android\Xamarin.Android.FSharp.targets" was not found. Confirm that the expression in the Import declaration "C:\Program Files\dotnet\sdk\3.1.101\\Xamarin\Android\Xamarin.Android.FSharp.targets" is correct, and that the file exists on disk. 1 Warning(s) 1 Error(s)
Conclusion (for now)
After working on this for a few days, I have to in all honesty say the experience of setting up the development environment is not a pleasant one. I like to keep my build process clean of any warnings or manual hacks, but at the moment, when it comes to F# Android development, this is does not seem possible to me.
For all of you saying: "why don't you use a completely different language/technology X/Y/Z?" or "you are dreaming a one-language-for-all utopia": I very much enjoy F# as a language and I wanted to see how easy it would be to develop Android apps with it (especially since I read a lot of good things about Fabulous and MVU pattern in general). So the priority here was not Android development itself, but more my attempt to leverage the knowledge of one technology in developing in a new environment. And also, after spending more than 20 years as a software developer in various technologies, I don't think I have yet encountered the one where "everything just works".
Having said that, at the moment, given what I've learned in the past few days, if I really wanted to develop for Android, I would probably try my luck with Kotlin, especially if I could found a stable MVU framework similar to Fabulous. But that's a topic for another investigation and another time.
So this is the point I got so far. My next attempts will be to check out Fabulous sample apps to find any steps/workarounds/hacks that I could use to make things smoother. I will be updating this post as I find more information.
As always, you can contact me on Twitter for any critique or suggestions.