I was excited to read today that SPI is now publishing the Android build status for all the packages they index! To quote directly from their blog post:
Plenty of work went into making Swift work on these platforms, and it seemed like a great time to add them to our compatibility testing. So we did! For the past week, the Swift Package Index build system has processed 35,000 builds to test compatibility. As of today, all builds are complete, and you can see Wasm and Android compatibility on every package page.
Results
Of ~9,000 indexed packages […] 27.9% build for Android. We find that remarkable, given that reliance on Apple-specific frameworks automatically makes many packages incompatible.
It’s safe to say that Swift is expanding beyond its Apple-focused roots. Windows and Linux have been officially supported for years, and Wasm and Android are starting to make their way down that path. It’s great to see.
Kudos to @daveverwer and @finestructure for getting this up and running (along with the WASM build status). This will be a great boon for developers who are assessing the level of effort needed to get their Swift projects working on Android.
Thank you Marc. We only took the final step. It wouldn't have been possible without all the contributions to get the project to the stage where this was possible.
Thank you Marc! It turned out to be a much simpler task than anticipated thanks to all the work you all have put into the SDK and the cross-compilation process It's wild that compiling for Android and Wasm is almost the same thing!
What are the numbers for linux and Windows, for comparison? Is there anything we can do right away to get Android closer to the linux number, or is it simply adding yet another import Android in a bunch of packages?
What are the numbers for linux and Windows, for comparison?
I expect Dave or Sven can answer more definitively, but based on swift-everywhere.org, 3,659 were building successfully for Linux, which is around 40% of their ~9k packages.
Is there anything we can do right away to get Android closer to the linux number, or is it simply adding yet another import Android in a bunch of packages?
In my experience, adding #if canImport(Android) import Android is the single most common way to get a package that was already building for Linux to build for Android. The nice thing about the SPI interface is that they link to the build failure logs, so for example you can see why the marmelroy/Zip package fails:
/host/spi-builder-workspace/Zip/Zip.swift:209:51: error: cannot find type 'FILE' in scope
207 |
208 | var writeBytes: UInt64 = 0
209 | var filePointer: UnsafeMutablePointer<FILE>?
| `- error: cannot find type 'FILE' in scope
I wrote a porting guide in the Skip blog post Bringing Swift Packages to Android, which expands on your own guidance. It could be interesting to trawl through the build failure logs and scan for common errors to see if there are any easy fixes.
I'll also take this opportunity to remind people about the Swift Android Action, which enables you to build and run all your test cases against an Android emulator as part of your GitHub CI workflow.