is there a way to AOT kotlin jvm apps
# compose-desktop
k
is there a way to AOT kotlin jvm apps
e
yes, GraalVM native-image
Compose Desktop uses Swing and GraalVM native-image claims to support Swing on Linux: https://www.graalvm.org/release-notes/21_0/#native-image:~:text=Added%20AWT%20and-,Swing,-support I have not tried it, though. I've only used native-image on CLI binaries
k
as apparently we can use
jaotc
but i dont know what to give it
e
jaotc doesn't exist anymore. use GraalVM native-image. https://openjdk.org/jeps/410
k
i tried passing the classes but i get
Copy code
> jaotc --compile-for-tiered --verbose --output DESKTOP.AOT --directory desktop\build\classes\kotlin\jvm\main

Compiling DESKTOP.AOT...

Found linker: C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\bin\Hostx64\x64\link.exe

Error: java.lang.NoClassDefFoundError: kotlin/jvm/functions/Function3
java.lang.InternalError: java.lang.NoClassDefFoundError: kotlin/jvm/functions/Function3
how would i do this using GraalVM
hmm
Copy code
> Configure project :desktop
e: C:\Users\clark\IdeaProjects\LuaJIT_Kotlin_MultiPlatform\desktop\build.gradle.kts:45:5: Val cannot be reassigned
e: C:\Users\clark\IdeaProjects\LuaJIT_Kotlin_MultiPlatform\desktop\build.gradle.kts:45:26: The boolean literal does not conform to the expected type Property<Boolean!>!
e: C:\Users\clark\IdeaProjects\LuaJIT_Kotlin_MultiPlatform\desktop\build.gradle.kts:46:5: Unresolved reference: main
e: C:\Users\clark\IdeaProjects\LuaJIT_Kotlin_MultiPlatform\desktop\build.gradle.kts:47:9: Unresolved reference: javaLauncher
e: C:\Users\clark\IdeaProjects\LuaJIT_Kotlin_MultiPlatform\desktop\build.gradle.kts:48:13: Val cannot be reassigned
e: C:\Users\clark\IdeaProjects\LuaJIT_Kotlin_MultiPlatform\desktop\build.gradle.kts:48:31: Type mismatch: inferred type is JavaLanguageVersion! but Property<JavaLanguageVersion!>! was expected
e: C:\Users\clark\IdeaProjects\LuaJIT_Kotlin_MultiPlatform\desktop\build.gradle.kts:49:13: Val cannot be reassigned
e: C:\Users\clark\IdeaProjects\LuaJIT_Kotlin_MultiPlatform\desktop\build.gradle.kts:49:22: Type mismatch: inferred type is JvmVendorSpec! but Property<JvmVendorSpec!>! was expected
Copy code
graalvmNative {
    binaries.all {
        resources.autodetect()
    }
    toolchainDetection = false
    main {
        javaLauncher = javaToolchains.launcherFor {
            languageVersion = JavaLanguageVersion.of(17)
            vendor = JvmVendorSpec.matching("GraalVM Community")
        }
    }
}
rip
Copy code
> Task :desktop:nativeCompile FAILED
[native-image-plugin] GraalVM Toolchain detection is enabled
[native-image-plugin] GraalVM uses toolchain detection. Selected:
[native-image-plugin]    - language version: 17
[native-image-plugin]    - vendor: GraalVM Community
[native-image-plugin]    - runtime version: 17.0.6+10-jvmci-22.3-b13
[native-image-plugin] Native Image executable path: C:\Users\clark\Downloads\graalvm-ce-java17-22.3.1\bin\native-image.cmd
Error: Please specify class (or <module>/<mainclass>) containing the main entry point method. (see --help)

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':desktop:nativeCompile'.
> Process 'command 'C:\Users\clark\Downloads\graalvm-ce-java17-22.3.1\bin\native-image.cmd'' finished with non-zero exit value 1
Copy code
graalvmNative {
}
copy and pastes
i still get the same error 😞
is this normal?
Copy code
Exception in thread "main" java.lang.NoSuchMethodError: java.awt.Toolkit.getDefaultToolkit()Ljava/awt/Toolkit;
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.jni.functions.JNIFunctions$Support.getMethodID(JNIFunctions.java:1259)
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.jni.functions.JNIFunctions$Support.getMethodID(JNIFunctions.java:1244)
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.jni.functions.JNIFunctions.GetStaticMethodID(JNIFunctions.java:413)
        at java.desktop@17.0.6/java.awt.Toolkit.initIDs(Toolkit.java)
imma just run java JIT version for now
m
Kotlin JVM apps in general can be AOT compiled via GraalVM/native-image but Compose apps cannot. This is due to several limitations. 1. GraalVM/native-image does not support AWT on all platforms. 2. Even if AWT is supported, e.g., by the Bellsoft NIK (which is derived from native-image) this still does not work because of some strange handling of the shared AWT library by JetBrains. Just have a look at these issues. https://github.com/bell-sw/Liberica/issues/94 https://github.com/JetBrains/skiko/issues/580 https://github.com/oracle/graal/issues/4124 https://github.com/oracle/graal/issues/4921
k
aw ok
would be nice if they could 🙂
522 Views