Hi! I am new to Desktop Compose and was just tryi...
# compose
m
Hi! I am new to Desktop Compose and was just trying a small Hello World! I just created a small app set up via File > New Project > Desktop Compose (which I assume comes from the Android plugin). However, when I run the app under macOS, then it fails with an error:
Copy code
WARNING: Secure coding is not enabled for restorable state! Enable secure coding by implementing NSApplicationDelegate.applicationSupportsSecureRestorableState: and returning YES.
I have 2 questions: 1) What is the development level of Desktop Compose (for MacOS), is it still alpha? 2) How do I fix the above problem: Gemini suggests to implement
MyApplication
that implements the
NSApplicationDelegate
but when I copy this code into the src/main/kotlin/Main.kt, the
NSApplication
and
NSApplicationDelegate
are unknown and there is no suggestion from where to import them. The generated project uses "org.jetbrains.compose.uidesktop ui1.6.10". (Please let me know if I should post the generated code. I am using IntelliJ Ultimate 2024.1.2 on arm64 MacOS.) Thanks for suggestions Melchior
1
k
Desktop compose is stable already. It uses JVM. Try to generate a new project via the web wizard
m
Where do I find the "web wizard" (it is not part of my installed Project generators)?
k
Try both
m
Thanks for the link to the wizard (I'll try a joint Android/iOS project), however the generated Desktop project has 2 problems: 1. when I run the gradle task "desktopRun" it says that there is not main class specified (and the jar is not executable), 2. when I open the main.kt and choose "run current class", the previous error returns:
Copy code
2024-06-08 15:47:05.315 java[51652:11244065] WARNING: Secure coding is not enabled for restorable state! Enable secure coding by implementing NSApplicationDelegate.applicationSupportsSecureRestorableState: and returning YES.

Exception in thread "main" java.lang.NoClassDefFoundError: androidx/collection/ScatterMapKt
	at androidx.compose.runtime.collection.ScopeMap.<init>(ScopeMap.kt:26)
	at androidx.compose.runtime.CompositionImpl.<init>(Composition.kt:479)
	at androidx.compose.runtime.CompositionImpl.<init>(Composition.kt:434)
	at androidx.compose.runtime.CompositionKt.Composition(Composition.kt:335)
	at androidx.compose.ui.window.Application_desktopKt$awaitApplication$2$1$2.invokeSuspend(Application.desktop.kt:219)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104)
	at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:318)
	at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:773)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:720)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:714)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:400)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:87)
	at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:742)
	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
	at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Caused by: java.lang.ClassNotFoundException: androidx.collection.ScatterMapKt
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:526)
	... 20 more

Process finished with exit code 1
Maybe, the problem is some missing / renamed class in the NSUIKit?
p
try run instead of desktopRun
m
Yes, that works, but I had to manually add the task to the gradle menu. Thanks for the tip.
👍 1
276 Views