Hello! Currently I developing library using kotlin/multiplatform. I want to make this library usable in other multi-platform projects. Let me explain what I mean. Currently I have modules:
lib/
sample_app/
Module “lib” contains shared library, which I want to export.
build.gradle file of “lib” module:
plugins {
id "org.jetbrains.kotlin.multiplatform"
}
kotlin {
sourceSets {
commonMain {
kotlin.srcDir('src/main')
dependencies {
implementation kotlin('stdlib-common')
implementation kotlin('reflect')
}
}
commonTest {
dependencies {
implementation kotlin('test-common')
implementation kotlin('test-annotations-common')
}
}
}
jvm().compilations.main.defaultSourceSet {
kotlin.srcDir('src/jvm')
dependencies {
implementation kotlin('stdlib-jdk8')
}
}
jvm().compilations.test.defaultSourceSet {
kotlin.srcDir('src/test')
dependencies {
implementation kotlin('test-junit')
}
}
}
build.gradle file of “sample_app” module:
plugins {
id "org.jetbrains.kotlin.multiplatform"
}
kotlin {
sourceSets {
commonMain {
kotlin.srcDir('src/main')
dependencies {
implementation kotlin('stdlib-common')
implementation kotlin('reflect')
implementation project(':lib')
}
}
commonTest {
dependencies {
implementation kotlin('test-common')
implementation kotlin('test-annotations-common')
}
}
}
jvm().compilations.test.defaultSourceSet {
kotlin.srcDir('src/test')
dependencies {
implementation kotlin('test-junit')
}
}
}
I need to build module “lib” to multiplatform library, which can be used as dependency in “commonMain”:
In sample_app/build.gradle I need to replace line
implementation project(':lib')
by
implementation file('my_library_file')
It needed to use this library as dependency in SHARED (!!!) code (“commonMain”), not separate for jvm and iOS, but exactly in shared code. Idea is to use this library in different projects to write shared code using it and publish this library later so others can use it in multiplatform projects.
I can’t find way how to build multiplatform library, only can build separately .jar and Apple Framework library, which cannot be used in shared code as dependency. Can anybody help with it?