Hi guys :wave: I am writting a KMP library and I w...
# multiplatform
r
Hi guys ๐Ÿ‘‹ I am writting a KMP library and I would want to have an API that is defined in the jvm source set, to also be available on android target. Such that android only apps can import the library and use this API. How can I achieve this? Do I have to replicate the code? I've tried to use
androidMain.dependsOn(jvmMain)
but my sample android app still cannot resolve this symbol related to this API defined on jvm source set ๐Ÿค”
s
You can not share jvmMain source-set between normal jvm(aka desktop) and android. You can create your own source-set and share between jvm desktop and desktop. I might have an example somewhere.
It has commonJvmMain which is shared between android and jvm desktop.
๐Ÿ™Œ 1
r
Ok great. Thank you so much ๐Ÿ™
m
r
Oh that looks nice.
Any way to do that without using
applyDefaultHierarchyTemplate
?
I don't know what that default hierarchy implies, I was assuming that for a library it would be better to manually define all dependencies
m
why would you not want to use
applyDefaultHierarchyTemplate
?
r
Like I said, I assumed this was mainly to facilitate dependsOn calls for applications. For libraries, having complete control makes sense in my mind. But I don't know if in practice, there's actually any harm in it ๐Ÿค”
m
If you want to visualize & have a look at how your hierarchy looks like, you can utilize https://github.com/terrakok/kmp-hierarchy plugin.
and if you want to read more about
applyDefaultHierarchyTemplate
take a look at the doc https://kotlinlang.org/docs/multiplatform-hierarchy.html#additional-configuration
r
I see. thank you! ๐Ÿ™‚
๐Ÿ‘Œ 1
m
it does create only the sourcesets that you have explicitly declared them. So it won't create any unnecessary source sets
r
Looks good yea. Maybe I can use it then. ๐Ÿ™Œ