Posix_spawnattr_init on Android 8.1 and earlier

I've updated my Android app to use Swift 5.4 and notice that it no longer works with Android 8.1 (API 27) and earlier.

It appears there was a change introduced in Process.swift to use posix_spawnattr_init, which is only available in Android 9 (API 28). This was changed with PR-2928 and PR-2942.

Was it intentional to drop support for the earlier versions?

CC @spevans / @Buttaface

No, in general, nobody much pays attention to Android, as it is not an officially supported platform. As you see with my Android pull #2942 you linked, that first pull broke compiling for Android till I fixed it a couple weeks later. I didn't really think about the API compatibility myself because I use Swift in the Termux app, which has a backported version of the official posix_spawn wrapper that works back to the API 24 that we use, so I just added a patch to link Foundation against that. You could use that too or simply revert Simon's tiny patch instead.

Thank you for the information. I will look into those options.

Just to follow up on this... Reverting the patch fixed the compatibility issue with Android 8.1 and earlier.

Vlad Gorlov has been doing a great job keeping an Android toolchain build up to date. He just released version 1.0.69 which includes Swift 5.4.

Ideally, you shouldn't need a full cross-compilation toolchain to cross-compile from macOS to Android and a much smaller Android SDK should be enough, but Vlad and I determined that the official macOS toolchain couldn't be used in this way, possibly because of some difference in the patches used in the official Swift 5.3 compiler for macOS and the OSS project. That's why he builds and distributes the OSS Swift compiler too.

However, the official Swift build of the Linux compiler works fine with an Android SDK, so that is what I tell people to use with my Android SDKs. I'll have them out for 5.4 soon.


I didn't realize you also had an SDK build. That's great. It's nice to have some options.

Terms of Service

Privacy Policy

Cookie Policy