Sachinda Liyanaarachchi
09/01/2022, 5:09 PMhfhbd
09/01/2022, 5:11 PMSachinda Liyanaarachchi
09/01/2022, 5:17 PMimplementation("dev.fritz2:core:$fritz2Version")
in commonMain
but when I try to build iOSApp it’s not recognizing this because this is a js library I believe. But I need this for a class in the shared
model folderhfhbd
09/01/2022, 5:20 PMSachinda Liyanaarachchi
09/01/2022, 5:26 PM@Lenses
data class Framework(val name: String) {
companion object
}
but this is giving me an error when I run the iosApp…hfhbd
09/01/2022, 5:33 PMSachinda Liyanaarachchi
09/01/2022, 5:39 PMCasey Brooks
09/01/2022, 5:44 PMcommonMain
code related only to your own business logic, and not to any platform- or ui-specific code. Classes that are used to configure or generate code for specific platforms are best kept in that platform’s own code, and you transform the Shared model into your Fritz2 model, for example. This isolates both the shared code and your Fritz code from each other in case one or the other changes in the future, making it much easier to update and maintain them both (at the cost of some additional boilerplate code).
A bit of a workaround would be to configure an additional sourceSet that is shared by the JVM and JS targets, but not iOS. A new fritzMain
sourceSet should be able to contain the Fritz2 dependency and share it between JVM and JS, but it’s not shared to iOS so it won’t cause an issue running iOS. Something like this should work (I’ve done this kind of thing succesfully with Compose before):
kotlin {
sourceSets {
val commonMain by getting {
dependencies { }
}
val fritzMain by creating {
dependsOn(commonMain)
dependencies {
implementation("dev.fritz2:core:$fritz2Version")
}
}
val jvmMain by getting {
dependsOn(fritzMain)
dependencies { }
}
val jsMain by getting {
dependsOn(fritzMain)
dependencies { }
}
val iosMain by getting {
dependsOn(commonMain)
dependencies { }
}
}
}
Sachinda Liyanaarachchi
09/01/2022, 5:47 PM