We have an issue with a Kotlin Native (KN) project...
# kotlin-native
j
We have an issue with a Kotlin Native (KN) project when running a class from a JVM module results in a NoClassDefFoundError on a class from the common module. If we run this class using Gradle, the code runs without problems. I have re-created the issue in a sample project we use to test new things and can be found here: https://github.com/jcraane/KotlinNativeStarter The project structure is as follows:
Copy code
root
    android
        app (Android application)
    common (multiplatform module (common code, iOS, Android and JVM)
    buildSrc (some custom Gradle tasks)
    iosApp (The iOS application)
    jvmmodule (The JVM module, this is were it is all about)
    localization (some custom localization code for Android and iOS)
The project is utilizing Kotlin 1.3.72 and Gradle 6.3. When checking out and importing the project into the IDE (Android Studio or IntelliJ) the problem is replicated by doing the following: Scenario 1 (running from the IDE) Actual: - Open the MyMainClass and click the Play icon in the gutter to execute the main method - The run window of the IDE outputs “Exception in thread “main” java.lang.NoClassDefFoundError: nl/jamiecraane/nativestarter/api/MockApi” Expected: - The main method is excuted and the response from the MockApi is displayed in the console Scenario 2 (running from Gradle) For this, we configured the Gradle application plugin to execute the MyMainClassKt. Run the following command from the command line: ./gradlew jvmmodulerun The result of this execution is the following (as expected, without a NoClassDefFoundError)
Copy code
> Task :jvmmodule:run
Hello
Response data: [Person(firstName=Jan, lastName=Janssen), Person(firstName=John, lastName=Smith)]
What can be the reason for this issue (NoClassDefFoundError when running the MyMainClass from the IDE instead of Gradle)?
There seems an open issue in the Jetbrains Kotlin issue tracker which address this issue: https://youtrack.jetbrains.com/issue/KT-38651