I use K/N in my Android/IOs project. Trying to mig...
# kotlin-native
a
I use K/N in my Android/IOs project. Trying to migrate from
konan
to the new
kotlin-multiplatform
plugin. Is it possible to have MPP library in the MPP project? I created an MPP library using IDEA's wizard, published it in maven local and tried to add to the project. But I have a gradle sync error:
Copy code
More than one file was found with OS independent path 'META-INF/FooMppLib.kotlin_module'
s
How do you add it to project?
a
In the app's `build.gradle`:
Copy code
//...
repositories {
//...
    mavenLocal()   //   <==
}
//...
kotlin {
    targets {
        fromPreset(presets.android, 'android')
        // This preset is for iPhone emulator
        // Switch here to presets.iosArm64 (or iosArm32) to build library for iPhone device
        fromPreset(presets.iosX64, 'ios') {
            compilations.main.outputKinds('FRAMEWORK')
        }
    }
    sourceSets {
        commonMain {
            dependencies {
                implementation 'org.jetbrains.kotlin:kotlin-stdlib-common'
                implementation 'com.example:FooMppLib-metadata:0.0.1'   //   <==
            }
        }
        androidMain {
            dependencies {
                implementation 'org.jetbrains.kotlin:kotlin-stdlib'
                implementation 'com.example:FooMppLib-jvm:0.0.1'   //   <==
            }
        }
//...
    }
}
//...
s
It should be enough to add
com.example:FooMppLib
to
commonMain
.
Also please ensure that Gradle 4.7 is used and metadata feature is enabled.
a
Thank you, it works! But I've noticed that I can use lib's api only on Android side. On iOs side only project's classes are available. Is it possible to use lib's classes from swift as well as project's classes?
s
I think there is an open issue to expose an included library’s classes. You should be able to force the include by having those classes exposed in your project’s public api as properties or function parameters. I had to do that with the Coroutines library.
s
Basic support for this is included to upcoming Kotlin 1.3.20 release.
💯 2
👍 1
a
Ok, thank you!
i
FYI: This feature is now added in Gradle plugins too. See the examples here: https://github.com/ilmat192/kotlin-native-gradle-samples/
👍 1