Cross-compilation SDKs for Android

There are now Swift 5.4 cross-compilation SDKs for AArch64, armv7, and x86_64 available, which you can use with a prebuilt Swift toolchain to cross-compile packages like swift-crypto or swift-system for Android with the Swift package manager.

Instructions on building and testing those packages on an Android device or emulator are in the README. Building with these SDKs is primarily tested on linux, but using them on Mac or Windows should be possible too.

I have set up a daily CI on github Actions that builds latest trunk of five Swift packages for all three architectures, then runs their tests for Android x86_64 in an emulator.

I plan to set up the same for the 5.5 branch snapshots and trunk, which will build the latest Swift SDK from source before testing it. I will also add some Swift scripts to automate the configuration of the SDK and building it.

Any suggestions of Swift packages to add to this Android CI are welcome, and you could use the CI script as an example to build or test packages yourself. Right now, the largest package tested on the CI is Swift NIO, which is about 60k lines of Swift code, about half tests.

I have also put out a Swift 5.4 toolchain that runs on Android in the Termux app, which can be used on Chromebooks that support running Android apps too.


With the release of Android NDK 23 a couple weeks ago, I've put together Swift 5.4.2 cross-compilation SDKs that can be used with this latest NDK.

The daily CI now builds the latest trunk commit of 11 Swift packages against all three Swift toolchains, ie 5.4.2 and the 5.5 and trunk snapshots, for the three Android architectures to make sure everything is still working. A few tests and packages are currently disabled from that matrix, for example, Swift NIO is only built by 5.4 because its tests currently can't be built by the 5.5 and trunk toolchains because of compiler regressions, which is reproducible on linux.

Building an Android SDK yourself is now easy because I added a Swift script to automate most of the setup. I will add a couple more Swift executables next, to similarly automate getting the Android SDK configured in your local environment.

Please report any problems by opening an issue on that github repo.


You might already have considered and rejected this, but it sounds like maybe the Source Compatibility Suite could be useful here?

That would be a good place to get ideas for Swift packages to add, but I doubt I will add server-oriented packages like Vapor. Some of the client-side packages make sense, but I may not need or be familar with them myself, pulls welcome.

As you can see with this pull adding two Swift packages, it is pretty easy. I need to switch the Android emulator to run on macOS soon, as it runs without hardware acceleration on linux in the github-provided CI VMs so the 11 testsuites take 90-120 mins. on there, as opposed to several mins. on my Android AArch64 phone.

1 Like
Terms of Service

Privacy Policy

Cookie Policy