How do I run desktop configuration from Android St...
# compose-desktop
s
How do I run desktop configuration from Android Studio? https://www.jetbrains.com/help/kotlin-multiplatform-dev/quickstart.html#run-the-sample-apps I've tried these 7 different approaches (all of which are valid destinations on my filesystem with the .kt extension removed): •
desktopRun -DmainClass=io.github.samuelmarks.off_on_ml.MainActivity --quiet
desktopRun -DmainClass=<http://io.github.samuelmarks.off_on_ml.App|io.github.samuelmarks.off_on_ml.App> --quiet
desktopRun -DmainClass=io.github.samuelmarks.off_on_ml.Greeting --quiet
desktopRun -DmainClass=io.github.samuelmarks.off_on_ml.Platform --quiet
desktopRun -DmainClass=io.github.samuelmarks.off_on_ml.Platform.jvm --quiet
desktopRun -DmainClass=io.github.samuelmarks.off_on_ml.main --quiet
desktopRun -DmainClass=io.github.samuelmarks.off_on_ml --quiet
s
Depends on where your main function resides. If it's at top level, in a file named
App
, you need to use
AppKt
as class name.
s
Copy code
Main method not found in class io.github.samuelmarks.off_on_ml.AppKt, please define the main method as:
From repo root, all .kt files:
Copy code
composeApp/src/androidMain/kotlin/io/github/samuelmarks/off_on_ml/MainActivity.kt
composeApp/src/androidMain/kotlin/io/github/samuelmarks/off_on_ml/Platform.android.kt
composeApp/src/commonMain/kotlin/io/github/samuelmarks/off_on_ml/App.kt
composeApp/src/commonMain/kotlin/io/github/samuelmarks/off_on_ml/Greeting.kt
composeApp/src/commonMain/kotlin/io/github/samuelmarks/off_on_ml/Platform.kt
composeApp/src/commonTest/kotlin/io/github/samuelmarks/off_on_ml/ComposeAppCommonTest.kt
composeApp/src/desktopMain/kotlin/io/github/samuelmarks/off_on_ml/Platform.jvm.kt
composeApp/src/desktopMain/kotlin/io/github/samuelmarks/off_on_ml/main.kt
composeApp/src/iosMain/kotlin/io/github/samuelmarks/off_on_ml/MainViewController.kt
composeApp/src/iosMain/kotlin/io/github/samuelmarks/off_on_ml/Platform.ios.kt
composeApp/src/wasmJsMain/kotlin/io/github/samuelmarks/off_on_ml/Platform.wasmJs.kt
composeApp/src/wasmJsMain/kotlin/io/github/samuelmarks/off_on_ml/main.kt
j
Probably should be MainKt then
Assuming the main method lives in that file as a top level function and it has no @file:JvmName
s
Nope that also didn't work. Here let me give you the repo: https://github.com/SamuelMarks/off_on_ml PS: I have also tried
desktopRun -DmainClass=io.github.samuelmarks.off_on_ml.OffOnMl.MainKt --quiet
🙌 1
o
I think I had to create a
object Main
where the
main
function resides.
mainApp.kt
(at root of source folder)
Copy code
object MainApp

fun main() {
  ...
}
In
mymodule/build.gradle.kts
Copy code
plugins {
    alias(libs.plugins.jetbrains.kotlin.jvm)
    ...
}

compose.desktop {
    application {
        mainClass = "MainAppKt"
        ...
    }
}
To launch it
Copy code
./gradlew :mymodule:run --quiet
I guess it should work with package as well
h
You don’t need the object
But how does your commonMain app.kt and your desktopMain app.kt look like? I assume, the fun main entrypoint is only defined in the desktopMain app.kt file? Because both common and the actual desktopMain file are named the same (AppKt.class), at runtime the wrong common class file is loaded first without the main function. => Rename desktopMain app.kt to app.desktop.kt (or use @JvmName with an unique name)
z
Is this a question because the run config that was automatically created by the KMP plugin didn't work, or it didn't generate one for you? Normally you should see a
moduleName [desktop]
run config which is set up correctly already. If that's not the case, and you could share the project in a YouTrack issue, that'd be really helpful: https://youtrack.jetbrains.com/newIssue?project=KMT
s
Ok happy to create an issue. Yeah I have literally modified 0 files [except README.md, and adding licenses]. I also tried all the default gradle tasks (clicking the 🐘 [gradle])