I have divided the shared part in to small modules as core, features and shared. The Shared module contains only koin implementation, coroutines adapter for iOS and build.gradle.kts where I have added the sub-modules as apis to consumed by both iOS and android.
This is working well on Android but in iOS the generated file doesn't contains the classes implementing sealed Interfaces in sub-module i.e. features.
As you can see above that it generates @protocol for the Intent -> SharedSXLIntent
but not @class is generated for GetAllLaunches
.
This is bit strange as this is working as expected when I added sealed interface and its implementation in the shared module it self.
Following is my kmm/shared/build.gradle.kts
file
`
plugins {
alias(libs.plugins.kotlin.multiplatform)
alias(libs.plugins.android.library)
alias(libs.plugins.kotlin.serialization)
}
kotlin {
android()
listOf(
iosX64(),
iosArm64(),
iosSimulatorArm64()
).forEach {
it.binaries.framework {
baseName = "shared"
}
}
sourceSets {
val commonMain by getting {
dependencies {
implementation(libs.kotlinx.datetime)
implementation(libs.kotlinx.coroutines.core)
api(project(":kmm:features:spaceXLaunches"))
api(project(":kmm:core:common"))
api(libs.koin.core)
}
}
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
}
}
val androidMain by getting {
dependencies {
implementation(libs.androidx.lifecycle.viewmodel)
}
}
val androidTest by getting
val iosX64Main by getting
val iosArm64Main by getting
val iosSimulatorArm64Main by getting
val iosMain by creating {
dependsOn(commonMain)
iosX64Main.dependsOn(this)
iosArm64Main.dependsOn(this)
iosSimulatorArm64Main.dependsOn(this)
dependencies {
}
}
val iosX64Test by getting
val iosArm64Test by getting
val iosSimulatorArm64Test by getting
val iosTest by creating {
dependsOn(commonTest)
iosX64Test.dependsOn(this)
iosArm64Test.dependsOn(this)
iosSimulatorArm64Test.dependsOn(this)
}
}
}
android {
sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
namespace = "com.arindom.cosmonaut"
compileSdk = libs.versions.compileSdk.get().toInt()
defaultConfig {
minSdk = libs.versions.minSdk.get().toInt()
targetSdk = libs.versions.targetSdk.get().toInt()
}
}
`
Im trying multi-module design inside shared code and expecting that it should generate the code for the respective platforms.
CodePudding user response:
You should add export
methods to get submodules implementation in your shared library. Please take a look at documentation.
In your kmm/shared/build.gradle.kts
in framework
section add
export(project(":kmm:features:spaceXLaunches"))
export(project(":kmm:core:common"))
It should look like this:
...
kotlin {
android()
listOf(
iosX64(),
iosArm64(),
iosSimulatorArm64()
).forEach {
it.binaries.framework {
baseName = "shared"
export(project(":kmm:features:spaceXLaunches"))
export(project(":kmm:core:common"))
}
}
sourceSets {
val commonMain by getting {
dependencies {
...
api(project(":kmm:features:spaceXLaunches"))
api(project(":kmm:core:common"))
...
}
}
...