Skip to content

Build fixes to allow using the epoll native transport on Android (#16…#16018

Merged
normanmaurer merged 1 commit into5.0from
android5
Dec 11, 2025
Merged

Build fixes to allow using the epoll native transport on Android (#16…#16018
normanmaurer merged 1 commit into5.0from
android5

Conversation

@normanmaurer
Copy link
Copy Markdown
Member

…016)

Note: more details are provided in the single commit messages.

Motivation:

the epoll native transport currently fails to compile on Android, due to a couple of compilation failures

transport-native-unix-common/src/main/c/netty_unix_errors.c:47:15: error: incompatible integer to pointer conversion initializing 'char *' with an expression of type 'int' [-Wint-conversion]
   47 |         char* tmp = strerror_r(errnum, strerrbuf, buflen);
      |               ^     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

and

transport-native-unix-common/src/main/c/netty_unix_socket.c:449:9: error: call to undeclared library function 'bzero' with type 'void (void *, unsigned long)'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
  449 |         bzero(&addr, sizeof(addr)); // Zap addr so we can strlen(addr.sun_path) later. See unix(4).
      |         ^
transport-native-unix-common/src/main/c/netty_unix_socket.c:449:9: note: include the header <strings.h> or explicitly provide a declaration for 'bzero'
  • netty_unix_socket.c uses bzero (in a single place). bzero is defined in strings.h, which however does not seem to be pulled in by default in Android with the current includes.
    Moreover, bzero is deprecated and was dropped in POSIX 2018. See POSIX 2018
    docs
    and relevant AOSP 16
    code
    .
  • netty_unix_errors.c currently uses the GNU strerror_r on Android. Android, however, only exposes the GNU strerror_r when _GNU_SOURCE is defined and only on API level 23+.
    See relevant AOSP 16
    code

Modification:

  • a dedicated repository was spun up to allow reproducing the build failures
  • it is an Android project containing the necessary plumbing to build the epoll native transport
  • it can be easily built by following the instructions in the README in the project repo
  • replace the deprecated bzero with memset, already used for the very same purpose in many places in the same file.
  • use the XSI strerror_r on Android, when _GNU_SOURCE is not defined

Result:

  • epoll native transport builds and Epoll.ensureAvailability() succeeds on Android.
    Tested on Android 16 emulator image BP41.250916.009.A1 (x86_64), NDK 27.0.12077973

Motivation:

Explain here the context, and why you're making that change.
What is the problem you're trying to solve.

Modification:

Describe the modifications you've done.

Result:

Fixes #.

If there is no issue then describe the changes introduced by this PR.

)

**Note**: more details are provided in the single commit messages.

## Motivation:
the epoll native transport currently fails to compile on Android, due to
a couple of compilation failures
```
transport-native-unix-common/src/main/c/netty_unix_errors.c:47:15: error: incompatible integer to pointer conversion initializing 'char *' with an expression of type 'int' [-Wint-conversion]
   47 |         char* tmp = strerror_r(errnum, strerrbuf, buflen);
      |               ^     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```
and
```
transport-native-unix-common/src/main/c/netty_unix_socket.c:449:9: error: call to undeclared library function 'bzero' with type 'void (void *, unsigned long)'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
  449 |         bzero(&addr, sizeof(addr)); // Zap addr so we can strlen(addr.sun_path) later. See unix(4).
      |         ^
transport-native-unix-common/src/main/c/netty_unix_socket.c:449:9: note: include the header <strings.h> or explicitly provide a declaration for 'bzero'
```
- `netty_unix_socket.c` uses `bzero` (in a single place). `bzero` is
defined in `strings.h`, which however does not seem to be pulled in by
default in Android with the current includes.
Moreover, `bzero` is deprecated and was dropped in POSIX 2018. See
[POSIX 2018
docs](https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xsh_chap03.html)
and [relevant AOSP 16
code](https://cs.android.com/android/platform/superproject/+/android16-release:bionic/libc/include/strings.h;l=69).
- `netty_unix_errors.c` currently uses the GNU `strerror_r` on Android.
Android, however, only exposes the GNU `strerror_r` when `_GNU_SOURCE`
is defined and only on API level 23+.
See [relevant AOSP 16
code](https://cs.android.com/android/platform/superproject/+/android16-release:bionic/libc/include/string.h;l=145?q=string.h)

## Modification:
- a [dedicated
repository](https://github.com/faenil/NettyEpollAndroidBuildFailureTest)
was spun up to allow reproducing the build failures
- it is an Android project containing the necessary plumbing to build
the epoll native transport
- it can be easily built by following the instructions in the `README`
in the project repo
- replace the deprecated `bzero` with `memset`, already used for the
very same purpose in many places in the same file.
- use the XSI `strerror_r` on Android, when `_GNU_SOURCE` is not defined

## Result:
- epoll native transport builds and `Epoll.ensureAvailability()`
succeeds on Android.
Tested on Android 16 emulator image `BP41.250916.009.A1` (x86_64), NDK
`27.0.12077973`
@normanmaurer normanmaurer added this to the 5.0.0.Final milestone Dec 11, 2025
@normanmaurer normanmaurer merged commit 49eaac3 into 5.0 Dec 11, 2025
10 of 13 checks passed
@normanmaurer normanmaurer deleted the android5 branch December 11, 2025 17:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants