Skip to content

Add Android support - #222

Merged
rpaulo merged 2 commits into
apple:mainfrom
finagolfin:droid
Oct 8, 2026
Merged

rpaulo merged 2 commits into
apple:mainfrom
finagolfin:droid

Conversation

@finagolfin

Copy link
Copy Markdown
Contributor

This package now compiles and all tests passed natively on Android built against API 24 with a Sep. 21 trunk snapshot toolchain and apple/swift-tls#23 applied to that dependency, though with the -Xswiftc -O flag added to work around swiftlang/swift#92886.

internal import Logging
#elseif canImport(Android)
import Android
internal import Logging

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All these imports were added by a regex substitution, then manually reviewed.

Comment thread Sources/SwiftNetwork/System/Darwin/DarwinResources.swift
#if os(Linux) || os(Android)
#if canImport(Glibc)
import Glibc
internal import SwiftNetworkLinuxShim

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This linux shim works on Android, but I removed it since it's unneeded.

@finagolfin

Copy link
Copy Markdown
Contributor Author

Rebased, added Android to CI, and made a formatting change to one file that the CI check wanted.

@rpaulo

rpaulo commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Looks like we need to fix this CI build error:

find: ‘/home/runner/work/swift-network-evolution/swift-network-evolution/.build/out/Products/Debug-android-x86_64’: No such file or directory
INFO         | Boot completed in 23943 ms
INFO         | Increasing screen off timeout, logcat buffer size to 2M.
WARNING      | adb command '/usr/local/lib/android/sdk/platform-tools/adb -s emulator-5554 shell cmd window set-ignore-orientation-request true ' failed: 'Unknown command: set-ignore-orientation-request'

I'm not familiar with Android, but do you know what's going on?

@finagolfin

Copy link
Copy Markdown
Contributor Author

Oh, didn't notice that you are switching back to the native build system for the nightlies on CI, any reason you still have that? That is causing the above Android error for the 6.4.x nightlies, as the 6.4 release works fine for Android, where that flag is not applied. The trunk build hangs, as do all the other builds using the linux toolchain right now because of the compiler issue I linked.

@rpaulo

rpaulo commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Oh, didn't notice that you are switching back to the native build system for the nightlies on CI, any reason you still have that? That is causing the above Android error for the 6.4.x nightlies, as the 6.4 release works fine for Android, where that flag is not applied. The trunk build hangs, as do all the other builds using the linux toolchain right now because of the compiler issue I linked.

Are you saying that nightly-6.4 doesn't work on Android? If that's the case, we can disable it for now in your CI changes.

@finagolfin

Copy link
Copy Markdown
Contributor Author

Are you saying that nightly-6.4 doesn't work on Android? If that's the case, we can disable it for now in your CI changes.

No, the issue is that the official GitHub workflows now only expect the Android SDK to be used with the swiftbuild build system, so they only look in that internal build directory for the test runners. I find it strange that you are still using the native build system for the nightlies alone on the CI here, do you know why that is?

@rpaulo

rpaulo commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

I think the --build-system native flag was to work around an issue on 6.5 (maybe). I think it's worth removing it now to see if it's still needed.

@finagolfin

Copy link
Copy Markdown
Contributor Author

OK, will try that here and see.

Comment thread .github/workflows/main.yml Outdated
@rpaulo rpaulo added the 🆕 semver/minor Adds new public API. label Oct 6, 2026
@rpaulo rpaulo added 🔨 semver/patch No public API change. and removed 🆕 semver/minor Adds new public API. labels Oct 6, 2026
Comment thread .github/workflows/pull_request.yml Outdated
@finagolfin

Copy link
Copy Markdown
Contributor Author

Hmm, most CI failing in this test that was added yesterday, some subsequent pull broke it?

@rpaulo

rpaulo commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Hmm, most CI failing in this test that was added yesterday, some subsequent pull broke it?

It's fixed now. Could you please rebase?

@finagolfin

Copy link
Copy Markdown
Contributor Author

@rpaulo, rebased, please run CI.

@finagolfin

Copy link
Copy Markdown
Contributor Author

The last rebase picked up a new linux/mac-only logging method: added it for Android and checked to make sure this branch builds on Android locally before updating now.

@finagolfin

Copy link
Copy Markdown
Contributor Author

Alright, all non-trunk builds are passing now, including the nightly 6.4.x Android SDK snapshots once I removed the change to the native build system. How about we get the first commit here in for Android support, then I will submit a separate CI-only pull to clean up those workflows for all platforms?

Comment thread .github/workflows/pull_request.yml Outdated

@rpaulo rpaulo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes look good, minor small nits. Probably wait for #226 before rebasing.

@finagolfin

Copy link
Copy Markdown
Contributor Author

No need to wait on #226, as all trunk builds fail because of the trunk compiler regression anyway.

@agnosticdev agnosticdev left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@finagolfin

Copy link
Copy Markdown
Contributor Author

Simply rebased to pick up changes that should get main CI working too.

@rpaulo

rpaulo commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

OK, now that #228 is merged, would the Android build succeed? If you think so, please rebase so we can try again.

@finagolfin

Copy link
Copy Markdown
Contributor Author

Rebased to pull in those CI config changes, yes, Android with the trunk SDK should work now, since that pull switched it back to the default swiftbuild build system.

@rnro rnro left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks

@rpaulo rpaulo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved. I don't see the Swift Network tests running on Android yet, but we could try to fix that in another PR.

@finagolfin

Copy link
Copy Markdown
Contributor Author

That is a separate issue with the official workflow that will be fixed upstream at some point, swiftlang/github-workflows#277.

throw NetworkError.posix(error)
}
#if canImport(Android)
guard let nameBuffer = if_indextoname(index, bufferAddress) else {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our internal review system flagged this as not following Linux which uses System.syscallOptional and retries on EINTR and saves errno correctly. Could we use syscallOptional on Android as well?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I threw that out for Android because it was unnecessarily converting the index to Int and then back again to UInt and I didn't see the point to that method, but I suppose I can create UInt overloads for Android.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added another commit that uses that method, tested as always by building and running the tests on my Android 16 phone, with this code first built against the Android 7 APIs.

@finagolfin

Copy link
Copy Markdown
Contributor Author

Simply rebased to avoid an incorrect API breakage check from subsequently merged pulls

@rpaulo
rpaulo merged commit 244c452 into apple:main Oct 8, 2026
42 checks passed
@finagolfin

Copy link
Copy Markdown
Contributor Author

Thanks for the quick review. 👍

@Cartisim, please take a look if you'd like anything else added.

@finagolfin
finagolfin deleted the droid branch October 8, 2026 19:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔨 semver/patch No public API change.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants