ar-g
02/23/2024, 4:56 PMgetByName("commonMain") {
dependencies {
implementation(libs...)
}
}
Pablichjenkov
02/23/2024, 5:17 PMtarget expander
module on your end that actually supports js. Then inside this module, use the library for Android/iOS and do your own JS implementation.Jeff Lockhart
02/23/2024, 5:58 PMar-g
02/23/2024, 6:33 PMkotlin {
sourceSets {
val commonMain by getting {
dependencies {
implementation(libs.yourCommonDependencies)
}
}
val iosAndroidCommonMain by creating {
dependsOn(commonMain)
dependencies {
implementation(libs.rustlib)
}
}
val iosMain by getting {
dependsOn(iosAndroidCommonMain)
}
val androidMain by getting {
dependsOn(iosAndroidCommonMain)
}
val jsMain by getting {
dependsOn(commonMain)
dependencies {
implementation(libs.mockrustlib)//or code it in module itself
}
}
}
}
Jeff Lockhart
02/23/2024, 6:54 PMjsMain.dependsOn(commonMain)
. You just might need an explicit call to applyDefaultHierarchyTemplate()
, since your usage of dependsOn
prevents it from being applied by default.
But even better, I prefer using the new source set hierarchy tree API, which is more concise and easier to read. It is still experimental, the API has just had a few minor mostly naming changes since it was introduced. You could do the same with:
kotlin {
@OptIn(ExperimentalKotlinGradlePluginApi::class)
applyDefaultHierarchyTemplate {
common {
group("iosAndroidCommon") {
withAndroidTarget()
group("ios")
// or withIos()
}
}
}
sourceSets {
val commonMain by getting {
dependencies {
implementation(libs.yourCommonDependencies)
}
}
val iosAndroidCommonMain by getting {
dependencies {
implementation(libs.rustlib)
}
}
val jsMain by getting {
dependencies {
implementation(libs.mockrustlib)//or code it in module itself
}
}
}
}
group("ios")
ties the default hierarchy's intermediate iosMain
source set in as the child source set, where withIos()
connects all the iOS target source sets directly. I prefer the former.