mmm111mmm
mmm111mmm

Reputation: 4085

Include a module as a dependency into a KMM project's shared module

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

How can I include a modules into KMM's shared module as a dependency?

Upvotes: 3

Views: 4198

Answers (1)

mmm111mmm
mmm111mmm

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

Related Questions