iOS
- App
SwiftUI
for the interface and Swift
as Language.
staticjava
hello
hello
directory
GRAALVM_HOME
, e.g. /opt/graalvm-jdk-23+23.1
javac -p /opt/graalvm-jdk-23+23.1/Contents/Home/jmods --add-modules org.graalvm.nativeimage hello/HelloStaticLib.java
/tmp/mycapcache
/bin/native-image \ -Ddebug.jdk.graal.jvmciConfigCheck=warn \ -Djdk.internal.lambda.eagerlyInitialize=false \ --no-server \ -H:+SharedLibrary \ -H:+ExitAfterRelocatableImageWrite \ -H:TempDirectory=/tmp/out \ -Dsvm.targetName=iOS -Dsvm.targetArch=arm64 -H:+UseCAPCache -H:CAPCacheDir=/tmp/mycapcache \ -H:CompilerBackend=lir -Dsvm.platform=org.graalvm.nativeimage.Platform\$IOS_AARCH64 \ -cp . hello.HelloStaticLib
/tmp/out/SVM-.... /hello.hellostaticlib.a, and generated headerfiles (graal_isolate.h and hello.hellostaticlib.h) are in the current working directory.
- Create a static lib from that objectfile:
ar rsc libmyapp.a /tmp/out/SVM-.../hello.hellostaticlib.o
ContentView.swift
to include some java calls by
overwriting it with this one.
myapp-Bridging-Header.h.
- In project settings (click on your project in the Project Navigator, then select your target), go to the "Build Settings" tab.
- Search for "Objective-C Bridging Header".
- Set the path to the bridging header file you just created, relative to your project’s root.
- copy the
graal_isolate.h
header to your project.
- Modify the bridging header file to include that file, e.g. add
#include "yourProject/graal_isolate.h"
- Add the exported java functions from your java file to the bridging header, e.g.
extern int javaSum(void* thread, int a, int b);
extern int javaDiff(void* thread, int a, int b);
- copy the
hello.hellostaticlib.a to your project
- Download the JDK libs from here and add it to your project
- Download the JVM libs from here and add it to your project
- In Project settings, Build Phases, add those 3 libs to
Link Binary with Libraries
, and also add libz.tbd
there.
Build and run!