I got a KMP hierarchy like this, and I am interest...
# gradle
s
I got a KMP hierarchy like this, and I am interested in sharing some code inside
jvmAndAndroid
which calls functions from kotlinx.datetime which lives inside the
jvm
target of that library. Particularly I am trying to use
import kotlinx.datetime.toJavaLocalDate
. When I copy-paste the exact same code inside
androidMain
and
jvmMain
I can call
toJavaLocalDate
without issues. If I try to call
toJavaLocalDate
inside
jvmAndAndroid
it is unable to resolve it at all. Is there a way for me to make this work, or is this a limitation due to the android and the jvm targets kinda being both jvm but not exactly?
👀 1
➕ 1
👍 1
h
How do you setup your dependencies?
s
In this case I was bringing in kotlinx.datetime in commonMain. I could try explicitly also doing
implementation(...kotlinx.datetime)
in the jvmAndAndroid source set too if that would work
o
The latter should not be necessary,
a
https://kotlinlang.org/docs/multiplatform/multiplatform-hierarchy.html#manual-configuration
Kotlin doesn't currently support sharing a source set for these combinations:
• JVM + Android targets
So the code in
jvmAndAndroidMain
can only access what is accessible in
commonMain
. If it's only one API, you can just use expect/actual. If you want to access all JVM APIs, I think you need to create a JVM module and make
androidMain
and
jvmMain
depend on that module.
➕ 1
👍 1
s
"create a JVM module and make..."
That would mean a separate Gradle project, correct?
a
A separate Gradle module.
👍 1