Skip to content

[Android] Gate getifaddrs behind API 24 availability - #3506

Merged
Lukasa merged 7 commits into
apple:mainfrom
madsodgaard:getifaddrs-availability
May 18, 2026
Merged

Lukasa merged 7 commits into
apple:mainfrom
madsodgaard:getifaddrs-availability

Conversation

@madsodgaard

Copy link
Copy Markdown
Contributor

The getifaddrs is only available on Android API 24+. So, to make swift-nio compile on API 23, we need to add @available annotations to the functions that use it. Which are just the two interface enumerate functions.

Result:

swift-nio can be compiled for Android 23.

/// - Throws: If an error is encountered while enumerating interfaces.
@available(*, deprecated, renamed: "enumerateDevices")
#if compiler(>=6.3)
@available(Android 24, *)

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.

I'm not sufficiently Android-aware to know this impact here. Did this compile for Android API 23 prior to Swift 6.3, and now does not?

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.

No, but we added @available support for Android in 6.3, that's why the compiler condition

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.

So what happened to this code in the 6.2 compiler?

@madsodgaard madsodgaard Feb 9, 2026 •

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.

It does not compile for Android 23, because the getifaddrs symbol is missing from the NDK in API 23 and below.

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 thing I'm trying to figure out is whether this change produces a break for anyone, where code that previously compiled now will not.

@madsodgaard madsodgaard Feb 9, 2026 •

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.

I don't think it would break anything. If you tried to compile swift-nio API 23 before, it would fail. The only place I could theoretically see it breaking was if someone was building swift-nio using a custom Android SDK and their own shim for getifaddrs and using one of the enumerate functions. Then they would get a error that it is only available on API 24.

But that's quite a stretch imo πŸ˜„

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.

Agreed. I believe we have (limited) Android CI. Is there a reason this isn't triggering compile failures there? https://github.com/apple/swift-nio/actions/runs/21817139179/job/62941167486

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.

Yeah, currently the Android SDK is only compiled for API 28+. That should soon be brought down to 24, and I am working on API 23 support as well. So that's why its not appearing in CI.

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.

Gotcha, thanks.

@Lukasa Lukasa added the πŸ”¨ semver/patch No public API change. label Feb 9, 2026
@Lukasa
Lukasa enabled auto-merge (squash) February 9, 2026 14:33
auto-merge was automatically disabled February 9, 2026 17:30

Head branch was pushed to by a user without write access

@finagolfin finagolfin 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.

Unfortunately, I think this will break building with NDK 27.

@finagolfin finagolfin 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.

Never mind, this works fine because all current SDKs only support Android API 24 or later.

@madsodgaard

Copy link
Copy Markdown
Contributor Author

The WASM CI failure seems network related? Also not sure whats up with the C++ interop failure? Does not seem related to this PR?

The most confusing is why the compiler check does not work for 6.0?

@Lukasa

Lukasa commented Feb 11, 2026

Copy link
Copy Markdown
Contributor

It seems like in 6.0 the compiler check is not ignoring the list of supported protocols: it's parsing it anyway. You may have to duplicate the entire method.

@madsodgaard
madsodgaard requested a review from Lukasa May 17, 2026 11:12
@madsodgaard

Copy link
Copy Markdown
Contributor Author

@Lukasa As 6.0 was dropped, the CI failure related to that should no longer be relevant. So this should be good to go πŸ‘

@Lukasa
Lukasa merged commit 0ee0fd1 into apple:main May 18, 2026
52 of 54 checks passed
@finagolfin

Copy link
Copy Markdown
Contributor

We are now shifting 6.4 to include API 23 also, but since that next Swift release will only support NDK 30 or later and drop support for NDK 27, which didn't have these availability annotations, I think this will work fine.

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.

3 participants