Reputation: 4085
I have a working KMM application, and I have a java module, mymodule
, that I created with File->New->Module->Java or Kotlin library
.
The module exists at the top level beside androidApp
, iosApp
and shared
. In my settings.gradle.kts
I have include(":mymodule")
.
I want to use mymodule
in the shared
module. So I go into the shared
module's build.gradle.kts
and I try to include my module in commonMain
:
kotlin {
...
sourceSets {
val commonMain by getting {
dependencies {
implementation(project(":mymodule"))
}
}
...
}
...
}
...
And the error is Could not resolve MyKMMApplication:mymodule:unspecified
and:
Could not resolve project :mymodule.
Required by:
project :shared
Things I've tried
dependencies { implementation(project(":mymodule")) }
at the bottom of shared
's build.gradle.kts
and but still the same error appearsmymodule
into the Android project without problemsimplementation("com.squareup.sqldelight:runtime:1.5.3")
in commonMain
and see those classes in the shared
module no problemHow can I include a modules into KMM's shared module as a dependency?
Upvotes: 3
Views: 4198
Reputation: 4085
So, the module you include into shared
needs to be a multiplatform module. It's build.gradle.kts
file should look something like this:
plugins {
id("org.jetbrains.kotlin.multiplatform")
}
kotlin {
jvm()
iosX64()
iosArm32()
iosArm64()
}
And it's project structure should look something like: mymodule/src/commonMain/kotlin/com/example/mymodule/
.
Upvotes: 3