In a project that uses both the `jvm` and `android...
# multiplatform
g
In a project that uses both the
jvm
and
android
targets, is there a way for the
android
implementation to default to the
jvm
target’s implementation for certain
expect
functions?
Some of my
actual
implementations are identical on both targets, so it’d be convenient and remove a lot of duplicated code.
Nevermind, I just had my source sets screwed up! If anyone else runs into this, you can make an additional source set with
create("<name>")
and add
dependsOn("<name>")
to any targets you want to use that default implementation. Ex:
Copy code
val jvmSharedMain = create("jvmSharedMain"){}
val jvmMain by getting {
    dependsOn(jvmSharedMain)
}
val androidMain by getting {
    dependsOn(jvmSharedMain)
}
👍 1
a
exactly, it follows a similar pattern to iosMain
m
If you only have
jvm
and
android
targets and you are not planning to add further targets in the future you can also just remove this
expect/actual
stuff and move the code to commonMain.