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

KamilH

10/01/2020, 10:39 AM
I want to be able to use
main
function inside
jvmMain
to test the library I’m working on, but when I’m trying to run main function it returns
Error: Could not find or load main class MainKt
for following function in
Main.kt
Copy code
fun main() {
    runBlocking {
        userRepository.registerUser("")
    }
}
Are there any additional steps I should make to be able to use this?
f

faogustavo

10/01/2020, 10:42 AM
is the JDK configured correctly for the project?
k

KamilH

10/01/2020, 10:47 AM
Are you referring to this one?
👍 1
f

faogustavo

10/01/2020, 10:51 AM
and on the target? Do you have something like this 👇?
Copy code
jvm {
            compilations.all {
                kotlinOptions.jvmTarget = "1.8"
            }
        }
k

KamilH

10/01/2020, 10:57 AM
Thanks! I didn’t have this, but I tried to add this and it still doesn’t work
🤔 1
I assume such
main
function is working in your case. That’s why I would like to ask you if you can choose your class (containing main) under “Edit configuration” -> “Main class”? When I’m trying to do it it’s either not finding the class or not allowing me to choose it
f

faogustavo

10/01/2020, 12:53 PM
Here works normally 🤔
is your function in the root? without any package?
even with the file in the root dir is working normally 🤔
m

mbonnin

10/01/2020, 1:51 PM
Main you need the args in the signature ?
fun main(args: Array<String>)
k

KamilH

10/01/2020, 1:58 PM
@faogustavo thank you for checking, everything seems the same on my side, so I have no idea why it’s not working @mbonnin it doesn’t help unfortunately What is more - I saw this discussion and message: https://kotlinlang.slack.com/archives/C3PQML5NU/p1588501634307700?thread_ts=1588441008.300900&amp;cid=C3PQML5NU and I cloned “PeopleInSpace” project and tried to run it there (according to the message I linked to) and it failed with exactly the same message, so I guess it must be a JDK (?) linking problem or something like that
f

faogustavo

10/02/2020, 8:40 AM
Thats curious, I’m having the same problem if I try to run with an android target 🤔
k

KamilH

10/02/2020, 8:44 AM
You mean main function inside
androidMain
?
f

faogustavo

10/02/2020, 8:45 AM
yep
k

KamilH

10/02/2020, 8:46 AM
You are lucky, because you at least can run it inside
jvmMain
which is not working in my case 🙂
f

faogustavo

10/02/2020, 8:51 AM
In this KMM project it doesn’t work even in the jvmMain 😬
k

KamilH

10/02/2020, 8:55 AM
That is really interesting
f

faogustavo

10/02/2020, 12:01 PM
maybe in the kotlin issue tracker https://youtrack.jetbrains.com/issues/KT, didn’t find any bug-report channel
s

Sebastian Sellmair [JB]

10/02/2020, 1:26 PM
Just because I am curious, you're trying to run a main function on your local machine. The main function is placed inside
androidMain
wich is a source set for an Android target, right?
Also, you do have a gradle based multiplatform project and you would like to execute the main function using IntelliJ over Gradle?
k

KamilH

10/02/2020, 3:37 PM
@Sebastian Sellmair [JB] I wanted to make it 100% clear so I decided to record short video showing steps to reproduce this problem (you can skip from 0:20 to 1:20). As you can see on the vide, I’m creating a new Library project in IntelliJ, I’m adding
main
function in the
jvmMain
module, I’m trying to run it and I’m getting an error. Next I’m commenting-out android-related stuff in
build.gradle
and trying to run main function again and now it works
f

faogustavo

10/19/2020, 11:44 AM
Any updates about this? I’m facing the same problem now 😬
k

KamilH

10/19/2020, 11:52 AM
I reported this here: https://youtrack.jetbrains.com/issue/KT-42486 And then it was merged with this one: https://youtrack.jetbrains.com/issue/KT-35890 (seems like a general problem with coexistence of Android and JVM targets in one project) I’m still using a workaround to comment-out Android specific stuff
f

faogustavo

10/19/2020, 11:58 AM
Noice!! I also saw on the 35890 ticket that if you add the
-cp $Classpath$
to the vmoptions it works too 🙂
k

KamilH

10/19/2020, 12:04 PM
Good catch, thanks. I will test it later 🙂
f

faogustavo

10/19/2020, 12:06 PM
If you want to take a look, I commited that on my repo (https://github.com/faogustavo/kached/commit/273222178fd69341df00870c2ebfd0e60cc65913). Just look for the
demo/gson-memory-demo/build.gradle.kts
file
🙇‍♂️ 1
if you need any help with that call me on PV that I try to help you out 🙂
k

KamilH

10/19/2020, 12:13 PM
Thank you! 🙂