https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
s

Simon Schubert

06/03/2020, 10:12 PM
🤯 I tried to google and search this slack but my jvm and android mpp project won't run. Android builds fine but for the jvm I click the green arrow button in my Main.kt main() function and get the following error: "Error: Could not find or load main class sample.MainKt". Is there something wrong with my gradle? Simplified version:
Copy code
plugins {
    id 'org.jetbrains.kotlin.multiplatform'
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'com.squareup.sqldelight'

kotlin {
    android("android")
    jvm("jvm")

    sourceSets {
        androidMain {
            dependencies {
                implementation kotlin('stdlib')
                implementation "com.squareup.sqldelight:android-driver:1.3.0"
            }
        }
        jvmMain {
            dependencies {
                implementation kotlin('stdlib')
                implementation "com.squareup.sqldelight:sqlite-driver:1.3.0"
                implementation "org.jetbrains.kotlinx:kotlinx-html-jvm:0.7.1"
            }
        }
    }
}
l

louiscad

06/04/2020, 3:20 PM
Did you try running from the command-line?
m

Michal Harakal

06/04/2020, 3:24 PM
In order to run it as jvm app you need an
application
plugin and you have to define main class there as
mainClassName = "main.kotlin.EntryPointKt"
but I didn’t managed to get this working in the same gradle module with android plugin. Maybe there is some trick with writing manifest file via task etc. I am also interessted in solution …
r

russhwolf

06/04/2020, 3:29 PM
The application plugin requires
jvm { withJava() }
and that doesn't work if you also apply the android plugin. You can work around that by doing your app-level configuration in a separate gradle module which consumes the shared code as a library
s

Simon Schubert

06/04/2020, 3:31 PM
Thanks a lot I will try that 👍