Hello, Java on Mobile

On this page, I keep track of the progress to build Java on mobile.

HelloFX for Mac and ios, new build

July 19, 2024 Download this custom graalVM build: graalvm-c4c41f64e2-java23-24.1.0-dev-darwin-gluon-4.zip.

HelloFX for Mac and ios

July 19, 2024

HelloFX for Linux and Android

July 18, 2024 updated July 19, 2024

We can now use Substrate without having to manually add jdk libs or jvm libs.

Tagging

July 13, 2024

I tagged the merge commit that allows to build the static libs in my fork with 24-mobile1

Building HelloFX on Android

July 5, 2024

As mentioned on July 1:

Use Gluon Substrate from https://github.com/johanvos/substrate/tree/jdk22

Follow the instructions from docs.gluonhq.com to run on Linux and build on Android.
However, the latest Java code used in the labsjdk requires more native functions that are not implemented in the static jdk libs for Java 18, which are used inside Substrate. Therefore, a build of the recent jdk libs is needed. You can find a build at jdklibs-android-aarch64-23.tgz. Use these libraries instead of the 18-based ones. This can be done by replacing
-L/home/johan/.gluon/substrate/javaStaticSdk/18-ea+prep18-9/android-aarch64/staticjdk/lib/static
with the link to the directory where you unpacked the new libs, e.g.
-L/tmp/jdklibs

How to build those jdklibs yourself? The libs that are uploaded here are built from openjdk/mobile, from commit deb4256a4d9cad7475a8eecad8860135bbdfd483

bash configure \
--enable-headless-only \
--with-boot-jdk=/opt/jdk-22 \
--with-build-jdk=/opt/jdk-23 \
--with-toolchain-path=/opt/android-ndk-r26c/toolchains/llvm/prebuilt/linux-x86_64/bin \
--with-sysroot=/opt/android-ndk-r26c/toolchains/llvm/prebuilt/linux-x86_64/sysroot \
--with-toolchain-type=clang \
--with-jvm-variants=minimal \
--host=aarch64-linux-android \
--target=aarch64-linux-android

cd build/android-aarch64-minimal-release
make static-libs
mkdir jdklibs
cp `find . -name "*.a"` jdklibs/
tar -zcvf jdklibs-android-aarch64-23.tgz jdklibs

Running HelloFX on Linux

July 1, 2024

Donwload GraalVM from which is based on https://github.com/johanvos/graal/tree/2024-june and the static labsjdk from https://github.com/graalvm/labs-openjdk/releases/tag/23%2B25-jvmci-b01. Use Gluon Substrate from https://github.com/johanvos/substrate/tree/jdk22 Follow the instructions from docs.gluonhq.com to run on Linux and build on Android.

Instructions for running Java library code

Follow the steps here

Three libraries are added to a regular XCode project:

The JDK libs are build from OpenJDK/Mobile and the JVM libs are built from https://github.com/johanvos/vmone.git. Binary downloads are available in the instructions.

Running static JDK class builds with GraalVM (June 6, 2024)

In order to validate the static JDK libs (e.g. libjava.a, libnet.a etc), I am using them in combination with GraalVM AOT and SubstrateVM (hence no libjvm.a from OpenJDK). This is now working fine on an iPhone. Using XCode, I can create a simple iOS app with SwiftUI, adding the required libs and run Java code. Steps are described here but will be automated as much as possible.

building the launcher for Linux x86_64 (May 24, 2024)

In a first step, I have a completely static JDK build for Linux that I use to run HelloWorld. The launcher I use for this is a modified version of the OpenJDK launcher. See status report here.

building the launchers (May 21, 2024)

See status report here.

building the static libs (May 11, 2024)

This branch contains 4 commits on top of the OpenJDK head (May 11, 2024) that allows building a static JDK for iOS/Android: https://github.com/johanvos/jdk/tree/android-may-2024

I started from the OpenJDK head and fixed issues one by one. While doing this, I tried to keep track of the changes I had to made (why/how). Those changes (that ended up in the commits) are documented here: