"Cross-platform Swift": Blog series and simple Apple/Android app

Hi,

More than a year ago, I started my personal research on how to port Swift to non-Apple platforms for a production app/library I maintain (I'll present that project in a different topic).

Today, I'd like to share, rather than promote, my "rambling logbook" with other fellow developers because I have finally attached a sample Android Studio project to showcase the most relevant findings of this long series.

The blog series

My blog series is called "Cross-platform Swift" and comes with fully buildable sources (MIT). The series is mostly a talkative journey with a few code snippets here and there to document patterns that worked for my project, plus a simple Android application built with CMake and the now official Swift Android SDK.

Why CMake?

The choice of CMake over SwiftPM comes from limitations I stumbled upon when I started, but SwiftPM has improved dramatically over time and some past considerations might not hold at the time being. Take them with a grain of salt.

The convenient aspect about CMake is that NDK builds are seamlessly integrated with Android Studio (Gradle), thus allowing fast incremental builds of the Swift code without any additional tool.

For what it's worth, one outcome of my research is a set of reusable CMake toolchains (MIT as well) to build a dynamic Swift library with a C ABI in just a few lines.

A simple Android/Swift app

In the latest post in particular, I go through how I bootstrap an Android app based on Kotlin, Jetpack Compose, and a Swift library with C/JNI bindings.

The first version of the app is intentionally dumb, with the only interaction being a Swift-encoded JSON in a Compose view. The focus is more on the build system to minimize the configuration boilerplate and the .apk footprint (16MB in release).

More meaningful code is coming in the few remaining articles.


At the end of the day, I did all this for myself, but if you find this work useful, I would truly appreciate it if you could share it with other Swift developers or communities.

Thanks for reading,

Davide

10 Likes