RFR: 8370659: [mobile] enable static-libs-image for Android

Julian Waters jwaters at openjdk.org
Mon Dec 22 13:46:34 UTC 2025


On Sun, 26 Oct 2025 16:10:09 GMT, Johan Vos <jvos at openjdk.org> wrote:

> This PR adds the changes required to compile libjvm.a and the classlibs using the latest upstream code.
> 
> Some notes:
> 
> To configure/make, the following configuration is recommended:
> 
> bash ./configure \
> --disable-warnings-as-errors \
> --openjdk-target=aarch64-linux-android \
> --with-boot-jdk=/opt/jdk-25 \
> --with-toolchain-path=/opt/android-ndk-r29/toolchains/llvm/prebuilt/linux-x86_64/bin \
> --with-sysroot=/opt/android-ndk-r29/toolchains/llvm/prebuilt/linux-x86_64/sysroot \
> --with-toolchain-type=clang
> 
> 
> After configuring the build, run
> `make static-libs-image`
> 
> Note that this requires Android NDK 29, which can be downloaded from https://developer.android.com/ndk/downloads 
> I only tested this using Linux. Mac/Windows builds may or may not work.
> 
> In `make/autoconf/flags-cflags.m4`, the minimum android version is set to 32 (`-target aarch64-linux-android32`). The reason for this is that this version comes with a version of bionic that supports thr_current. This is not strictly needed, but lower versions would require more bionic-specific patches.
> 
> I use `#ifdef  __BIONIC__ `and similar in most places where we do "Android" specific checks. The reason for this is that those checks mainly refer to support that is (or isn't) available in Bionic. As such, it is better to compare e.g. bionic with musl and libc unless we are specifically using Android API's
> 
> I can provide a sample with a Makefile that validates the build on a real phone, but I think that is not in scope of this PR.

Build changes look ok, apart from some queries.

I believe you can use the touch command to keep a Pull Request open nowadays, it's quite a nifty tool to refresh the Pull Request without those keep alive comments :)

I'm not a Reviewer, so can't really help with getting this integrated, but something general I've noted is the #ifdef code for __BIONIC__ seems to not have a replacement for Android, it just doesn't include the code it guards on Android, but also doesn't implement it for Android either. So there's functionality in Java that is unimplemented and will simply not work on Android. Also, the build system seems to have "android" properly set in some areas (Like OPENJDK_TARGET_OS) while in others it re-uses "linux", which makes it a bit harder to see what is for Android and what is for Linux. Are both intentional? Otherwise, this seems fine. Just a couple other not-too-serious queries.

make/autoconf/flags-cflags.m4 line 73:

> 71: 
> 72:   # Debug symbols
> 73:   if test "x$TOOLCHAIN_TYPE" = xgcc || test "x$OPENJDK_TARGET_OS" = xandroid; then

What gcc flags does Android need that can't be done in the clang block?

make/autoconf/flags-cflags.m4 line 435:

> 433:     CFLAGS_OS_DEF_JVM="-D_WINDOWS -DWIN32 -D_JNI_IMPLEMENTATION_"
> 434:   elif test "x$OPENJDK_TARGET_OS" = xandroid; then
> 435:     CFLAGS_OS_DEF_JVM="-target aarch64-linux-android32 -DLINUX -D_ALLBSD_SOURCE -DANDROID"

Interesting that -target is needed, I thought --openjdk-target would handle that. Admittedly however I'm not very experienced with clang/LLVM, my area of expertise is more related to gcc.

src/hotspot/share/utilities/forbiddenFunctions.hpp line 54:

> 52: // avoided entirely.
> 53: 
> 54: #if !defined(__BIONIC__)

Ugh. I was never a fan of the way forbidden methods were poisoned in HotSpot, looks like the fallout has reached mobile. I'll do what I can to make upstream's implementation of it less painful to work with in the future.

-------------

Marked as reviewed by jwaters (no project role).

PR Review: https://git.openjdk.org/mobile/pull/40#pullrequestreview-3604112007
PR Comment: https://git.openjdk.org/mobile/pull/40#issuecomment-3682121664
PR Review Comment: https://git.openjdk.org/mobile/pull/40#discussion_r2639905252
PR Review Comment: https://git.openjdk.org/mobile/pull/40#discussion_r2639916019
PR Review Comment: https://git.openjdk.org/mobile/pull/40#discussion_r2639921383


More information about the mobile-dev mailing list