https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
m

MR3Y

09/30/2023, 4:36 PM
Is it possible to have a shared sourceset for Jvm(Desktop) + Android? citing Kotlin documentation:
Kotlin doesn't currently support sharing a source set for these combinations:
• Several JVM targets
• JVM + Android targets
• Several JS targets
There is no official solution, but I'm wondering if there is a workaround/hack I can use, I looked at the official samples/templates and other multiplatform projects but couldn't find a solution.
j

Jeff Lockhart

09/30/2023, 4:57 PM
It is possible. In general it should work, but it might depend what your dependencies are and how you're sharing code, what APIs you're using in the shared source set. In some cases you might need workarounds, as there isn't a commonizer, like Kotlin/Native source sets have. I have a jvmCommon source set in my library.
m

MR3Y

09/30/2023, 5:03 PM
I'm not targeting Kotlin/Native currently, Mainly I wanted a shared source set between Jvm + Android to avoid duplicate
actual
implementations like using Okhttp for example as an http client. Anyway, thanks for the repo, will try it out and see if it works
j

Jeff Lockhart

09/30/2023, 5:07 PM
If you're only accessing Java and Kotlin APIs that are common between JVM and Android targets, or dependencies with a common artifact, it should work just fine.
e

ephemient

09/30/2023, 11:18 PM
if you don't have any Android-specific code or dependencies, try just using a single JVM source set. Android consumers can use JVM libraries
👆🏼 1
👆🏾 1
j

Jeff Lockhart

10/01/2023, 12:17 AM
Yes, a shared JVM + Android source set only makes sense if you also have the need for at least some code in the android or jvm source sets, or an Android-specific dependency, that requires an Android-specific build.
m

MR3Y

10/01/2023, 12:44 AM
@ephemient Yeah, this is a good approach but, Unfortunately I have a few android specific dependencies So, I'am using Jeff's setup and it works well so far.
e

ephemient

10/01/2023, 12:45 AM
IntelliJ had some issues with that setup in the past, but it should generally work now AFAIK
m

MR3Y

10/01/2023, 12:48 AM
I was worried about that but after I tried it, I didn't get any IDE errors
2 Views