Skip to content

At last, the Dummy Counter runs on postmarketOS!

Posted in Stuff

Previously, I have been experimenting with Linux mobile options on the PinePhone. While I found some success getting a .NET Core app running on some platforms like Plasma Mobile and Ubuntu Touch, I failed to do the same on lighter mobile Linux systems like postmarketOS. Let’s see if we can enter a world where my Dummy Counter runs on postmarketOS.

A while back I reset that PinePhone of mine with a clean postmarketOS to get rid of all the shenanigans from my previous fiddlings. Since my code hadn’t changed since the last time, I figured I could try and find a different runtime to compile it. A runtime that might work with an arm64 alpine-based Linux which postmarketOS is. This is when I found that Github issue from early 2019 which Microsoft resolved in December 2020. This issue is about supporting the linux-musl-arm64 runtime, the arm64 Alpine Linux one.

The famous Github issue

From there, I decided to try and see what happens if I pass the linux-musl-arm64 parameter to build the app. After deploying the app to the PinePhone, I see that there are no linking errors and I get straight to the final result of my last post. You know, the segfault. No need to fiddle with libraries nor to create symbolic links all over the place. It linked well, but still no launching.

Once I reach that point again, something hits me. What if more happened over the past few years that flew me by? Maybe I can update the dependencies, it might not do much but at least I can investigate my issues with the latest version of each library.

Unfortunately, unless you use Visual Studio there is no option to update all your dependencies. So basically you need to do that library by library. Lucky for me there are only five to handle.

Extract from my DummyCounter.csproj project file

The command to add or update a package follows the following format:

dotnet add <PROJECT_FILE> package <PACKAGE_NAME>

And yes, if we wanted, we could have skipped the project file bit if we moved into the project folder and have something like that instead: dotnet add package Avalonia. However, since I like to run more complete versions of commands we will go with those below:

dotnet add DummyCounter/DummyCounter.csproj package Avalonia
dotnet add DummyCounter/DummyCounter.csproj package Avalonia.Desktop
dotnet add DummyCounter/DummyCounter.csproj package Avalonia.Diagnostics
dotnet add DummyCounter/DummyCounter.csproj package Avalonia.ReactiveUI
dotnet add DummyCounter/DummyCounter.csproj package SkiaSharp.NativeAssets.Linux

After running the Avalonia.Desktop update command, we start seeing an error that will appear all the way through.

error: NU1605: Detected package downgrade: SkiaSharp.NativeAssets.Linux from 2.88.0-preview.178 to 2.80.3-preview.40. Reference the package directly from the project to select a different version. 
error:  DummyCounter -> Avalonia.Desktop 0.10.13 -> Avalonia.Skia 0.10.13 -> SkiaSharp.NativeAssets.Linux (>= 2.88.0-preview.178) 
error:  DummyCounter -> SkiaSharp.NativeAssets.Linux (>= 2.80.3-preview.40)

The error basically means that we reference a lower version of the SkiaSharp.NativeAssets.Linux library in comparison to the one that the new Avalonia Desktop references. We will fix that once we update SkiaSharp.NativeAssets.Linux properly.

Once you’ve run all the update commands you will notice that the error is still there. Since the version of SkiaSharp.NativeAssets.Linux that we need is in preview, we need to boost that update command. We can do so by allowing the installation of pre-release versions with the --prerelase parameter.

dotnet add DummyCounter/DummyCounter.csproj package SkiaSharp.NativeAssets.Linux --prerelease

At last, the error is gone. Now we can finally build and run our application on a Desktop to be sure it still works as expected. It should still work since we only updated libraries. However, it is not uncommon to find breaking changes in library updates that require code changes.

Still works

Now that we know this still runs fine, let’s jump into the fun stuff. Let’s use the Makefile below, we can build and deploy our app to the postmarketOS-powered PinePhone:

Here we will use the command below:

make clean-publish-local

Alright let’s see what happens:

The Dummy Counter runs on postmarketOS!

And it finally worked, now we have an application that runs on postmarketOS and most likely on all Linux mobile platforms. Sure it doesn’t do much and there seems to be a bug with the button background but we’re heading in the right direction.

As a bonus, here is the Gitlab repository containing the codebase you’ve been waiting for. I hope you’ve learned something today and I will see you next time.

Cover Photo by Mikhail Nilov

Be First to Comment

    Leave a Reply

    This site uses Akismet to reduce spam. Learn how your comment data is processed.

    %d bloggers like this: