Kotlin JVM+Native Modules

Good afternoon, when i was doing a multi-platform application(Android/iOS), I got a some problems, does anyone know how to solve them?

  1. I have two kotlin native module(2 framework)

CORE

apply plugin: 'konan'
konanArtifacts {
    framework('KC', targets: ['iphone_sim']) {
        enableMultiplatform true
        enableOptimizations true
        enableDebug true
        dumpParameters false
        measureTime false
    }
}

WIZARD

apply plugin: 'konan'
konanArtifacts {
    framework('KP', targets: ['iphone_sim']) {
        enableMultiplatform true
        enableOptimizations true
        enableDebug true
        dumpParameters false
        measureTime false
    }
}

How i can add core to wizard module like compile project(:core) in JVM gradle?

  1. I have two common(expect) module:

CORE-COMMON

apply plugin: 'kotlin-platform-common'

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-common:$kotlin_version"
    compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    compile "org.jetbrains.kotlinx:kotlinx-coroutines-core-common:0.24.0"
}

PROJECT-EXPECT

apply plugin: 'kotlin-platform-common'

dependencies {
    compile project(":core-common")
    implementation "org.jetbrains.kotlin:kotlin-stdlib-common:$kotlin_version"
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}

Line compile project(":core-common") work for actual module JVM. But when I compile actual module for Native, compiler can not find classes from core-common. How include this(core-common) module inside project-expect that make JVM and Native implementation is work?(I know that i can move all classes from core-common to project-expect and this will be working)

Per https://github.com/JetBrains/kotlin-native/blob/master/GRADLE_PLUGIN.md#using-libraries, probably like libraries { artifact { project(':core') } }

Not sure on this one, but I’d like to know too. Assuming you have enableMultiplatform true and the expectedBy and what not in the native project, I suspect that it’s just an issue w/ Kotlin native and transitive common multiplatform dependencies. Maybe try two separate expectedBy in the native project to each project specifically?

Per https://github.com/JetBrains/kotlin-native/blob/master/GRADLE_PLUGIN.md#using-libraries, probably like libraries { artifact { project(':core') } }

I did it, but got this error:

Could not find method artifact() for arguments [build_29i4eu4nawqtq9rs45te5qfkj$_run_closure1$_closure3$_closure4$_closure5@2b8ccd54] on object of type org.jetbrains.kotlin.gradle.plugin.KonanLibrariesSpec.

konanArtifacts {
    framework('KP', targets: ['iphone_sim']) {
        libraries { artifact { project(':core-ios') } }
        enableMultiplatform true
        enableOptimizations true
        enableDebug true
        dumpParameters false
        measureTime false
    }
}

Sorry, it’s a method, so probably libraries { artifact project(':core') } or something similar. You can peek at the gradle plugin code anytime you are unsure about what you can and can’t do.

I’m tried both, but result is one:

Could not find method artifact() for arguments [project ‘:core-ios’] on object of type org.jetbrains.kotlin.gradle.plugin.KonanLibrariesSpec.

In example this:

artifact project(':bazProject'), 'bazLibrary' 

Maybe need this?

allLibrariesFrom project(':subproject')

Or artifact project(':core'), 'coreLibrary' or something…I should probably just stop guessing here and let someone debug this for you :slight_smile:

Just i’m not sure that i should specify here coreLibrary. Anyway thanks for your answer.