Skip to content

[Android] Gate getifaddrs behind API 24 availability#3506

Open
madsodgaard wants to merge 5 commits intoapple:mainfrom
madsodgaard:getifaddrs-availability
Open

[Android] Gate getifaddrs behind API 24 availability#3506
madsodgaard wants to merge 5 commits intoapple:mainfrom
madsodgaard:getifaddrs-availability

Conversation

@madsodgaard
Copy link
Copy Markdown

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
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?

Copy link
Copy Markdown
Author

@madsodgaard madsodgaard Feb 9, 2026

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.

Copy link
Copy Markdown
Author

@madsodgaard madsodgaard Feb 9, 2026

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
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

Copy link
Copy Markdown
Contributor

@finagolfin finagolfin left a comment

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.

Copy link
Copy Markdown
Contributor

@finagolfin finagolfin left a comment

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
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
Copy link
Copy Markdown
Contributor

Lukasa commented Feb 11, 2026

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.

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