SIMONE FRANCO | BLOG

_

September 14, 2020

Hello! Welcome to the first blog post ever on my website!

Today I want to talk about Uno Platform – an ambitious technology that I stumbled upon while catching up on tech news a few months back. The moment I saw it I knew I had to find out more.

"What? A single codebase and I can run that everywhere?" I told myself, couldn't believe that. We've already seen this idea with Microsoft's Universal Windows Platform, that aimed to let developers write apps once and run them on every device running Windows 10.

But Uno promises way more, since not only it covers UWP apps, but also supports Android, iOS, macOS, Web Assembly and now, with the Skia support, various Linux Distros and even Windows 7.

Wow. Honestly. I don't consider myself a particularly advanced developer, and I'll say this outright: I have no idea how Uno Platform works and what happens behind the scenes when I compile. Working on my projects, turning ideas into apps and writing spaghetti code, I’ve always wanted to be able to deploy to as many platforms as possible. Discovering Uno meant that my developer dream came true.

I have built an app for myself and some friends in the past months that I sadly can't show, but the result was incredible. My target was Windows 10 and Android. The performance is good, the app looks the same on all devices, and I've written the code only once. It did need a little bit of extra attention on Android in the form of a few lines of code, but the rest (around 99% of the code) is shared across both targets.

Let's try to build something from scratch to show the potential of Uno. If you want to follow me and try experimenting, I'll consider you have already followed the setup guide on Uno Blog. This is not a guide, but rather a summary of the work I do on my own project.

Getting started 💻

Once the Project Templates are installed as explained in the guide, let's create the Project.

And here we go. We have our project ready, with all the targets on the Solution Explorer.

We're ready to work! The workflow is quite easy: you’ll want to treat the .UWP project as your primary debugging target in the initial stages while keeping as much generic content as possible in the .Shared project. This includes XAML, regular C# code, as well as resources. Once you’re satisfied you can move onto debugging other platforms, fixing any issues if they happen to crop up. As you continue to implement more features, be sure to test them out on every platform.

Let's make a few edits to MainPage.xaml, take a look at MainPage.cs and the other files. You will immediately notice these match those of a regular UWP app. I'll build and run the project for UWP and for Android, and...

Moving on ➡

Wow! Would you look at that! UWP and Android with zero pain, single code base.

But this is just the template project. Let's work on something!

My plan is to make a simple SoundCloud client for Windows and Android, starting first with simple features and try expanding it as I work my way to show more Uno Platform features. Maybe I'll try to expand the targets as well.

Unfortunately, the official SoundCloud API is slowly stopping to work, so I'm trying to build over what's left. Let's create a login page, a "now playing" page, and talk to a few HTTP endpoints in their API to obtain some data.

This first version obtains and plays a single, specific song, and while it allows to log in to SoundCloud, it doesn't make use of it. It does play music on both OSes by using the same APIs however. Here's the result:

Issues ⛔

System.Text.Json is not supported on Android. I initially used it to parse the responses from SoundCloud, and it worked on UWP, but then I had to switch to Newtonsoft.Json (you can find it on NuGet) to make it work on Android as well.

Windows.Web.Http is not supported on Android. I've used System.Net.Http.

What's next 👾

As you can see, not everything is supported, but Uno has been making huge steps forward, and with each update more and more features are supported. Next time we'll build upon this (if the SoundCloud API allows me - Hey, SC devs, in the really improbable case you are reading this, please help, let me use your new APIs). The plan is to implement search, so I'll be able to showcase custom controls and the MVVM pattern at work with Uno.

Are you interested in Uno? Please visit their website!

You can find the source code for this example and compiled releases here

Thank you for reading, and please look forward for what's next (〃 ̄︶ ̄)人( ̄︶ ̄〃) I hope you enjoyed this blog post! Feel free to reach to me to discuss on Twitter and Telegram, you can find the links on the bottom of this page.