Skip to content

Support building native libraries with Android NDK 18+ - #1744

Merged
matthiasblaesing merged 1 commit into
java-native-access:masterfrom
BugsBeGone:android-ndk-llvm
Nov 2, 2026
Merged

matthiasblaesing merged 1 commit into
java-native-access:masterfrom
BugsBeGone:android-ndk-llvm

Conversation

@BugsBeGone

Copy link
Copy Markdown
Contributor

Backwards compatible changes to native makefile, such that ancient GCC-based toolchains can still be used, but also allow newer LLVM-based tools from NDK 18 onwards.

When building with anything available from the Android SDK manager currently, all that should be necessary is to set $NDK to the top-level path, and $NDK_PLATFORM to the target SDK level. If no Pkg.Revision can be found, you will also need to set $NDK_VER to the major version.

Checks for armv5 & MIPS target architectures are also performed, which are not supported from NDK 17,

@BugsBeGone

Copy link
Copy Markdown
Contributor Author

Forgot to mention, I have no opinion whatsoever about whether the shipped binaries should actually be upgraded or not, I understand that testing anything like this is extremely tedious at the best of times. This is purely intended to help those wanting to build jnidispatch.so from source, who may at some point be unable to use or even obtain ancient NDK toolchains.

@BugsBeGone BugsBeGone changed the title Support Android NDK 18+ (#1659) Support building native libraries with Android NDK 18+ Oct 20, 2026

@matthiasblaesing matthiasblaesing left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you. The changes make sense to me. For the change to the build instructions for Android please update to this:

Sample build
------------

NDKs with version > 16

```bash
export NDK=/home/matthias/Android/Sdk/ndk/30.0.16248370
export NDK_PLATFORM=21
export PATH=$NDK/toolchains/llvm/prebuilt/linux-x86_64/bin/:$PATH
ant -Dos.prefix=android-aarch64
ant -Dos.prefix=android-armv7
ant -Dos.prefix=android-x86-64
ant -Dos.prefix=android-x86
```

NDKs with version <= 16

```bash
export NDK=/home/matthias/bin/android-ndk-r12b/
export NDK_PLATFORM=21
export PATH=$NDK/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/:$PATH
export PATH=$NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/:$PATH
export PATH=$NDK/toolchains/mips64el-linux-android-4.9/prebuilt/linux-x86_64/bin/:$PATH
export PATH=$NDK/toolchains/mipsel-linux-android-4.9/prebuilt/linux-x86_64/bin/:$PATH
export PATH=$NDK/toolchains/x86-4.9/prebuilt/linux-x86_64/bin/:$PATH
export PATH=$NDK/toolchains/x86_64-4.9/prebuilt/linux-x86_64/bin/:$PATH
ant -Dos.prefix=android-aarch64
ant -Dos.prefix=android-armv7
ant -Dos.prefix=android-arm
ant -Dos.prefix=android-mips64
ant -Dos.prefix=android-mips
ant -Dos.prefix=android-x86-64
ant -Dos.prefix=android-x86
```

I tested with 27c and build succeeded. I tested building with 12b and got bit identical results compared to the current binaries.

While it is great to be able to build with recent NDKs, I have no plans to switch. We loose platforms without clear benefits.

@BugsBeGone

Copy link
Copy Markdown
Contributor Author

Sure, kept the original sample build docs with updated paths.

While it is great to be able to build with recent NDKs, I have no plans to switch. We loose platforms without clear benefits.

Makes sense. Unless someone is building with NDK target API of 25+, there is no need to switch. But the way Android have been dropping support for old versions, and forcing updates to include 64-bit & particular page alignment, I wouldn't be surprised if eventually there is a requirement for all native libraries to be built with tools that allow targetting more current APIs.

@matthiasblaesing

Copy link
Copy Markdown
Member

Thank you.

@matthiasblaesing
matthiasblaesing merged commit c012e67 into java-native-access:master Nov 2, 2026
12 checks passed
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