It seems like best practice for a while was to hav...
# multiplatform
e
It seems like best practice for a while was to have separate app modules for each target (e.g. android, ios, wasmJs, etc...), but now I've seen several projects having one app module with separate source sets for the different targets. Is there official guidance for this, and if not, is there any good write up of the pros and cons of the two approaches?
j
JetBrain's older templates had separate app modules. But the current template used by kmp.jetbrains.com has a single module. My guess it was an effort to simplify getting started, where there's only one place you need to understand putting platform-specific code.
👍 1
p
Same opinion, it was an effort to welcome newcomers I guess. Big projects will go multiple modules anyway.
y
I guess also as you are sharing more code, KMP libraries like Apollo, Ktor. Or using expect/actual. The target platform is an awkward way to modularise.
✔️ 1
Modules might be more around features or form factors.
e
> separate app modules for each target This was a very strange paradigm. The expect and actual declarations were fragmented over multiple places, making it very hard to handle a consistent amount of except declarations. Edit: I see this seems to be Compose-specific, but yes there was a time when expect/actual were split by module
p
Definitely
the target platform is an awkward way to modulirize
It sounds to me, at the beginning, the App module per target was better to mix with an existing target code. Perhaps more oriented to show devs how to
integrate
with existing code. Which is still one of the biggest selling points.
e
Maybe it's different for me because my project is highly modularized, and the apps for the different platforms have little to no shared code because they're just entry points.
p
For your case I agree that 1 module for all targets is more than enough.
p
I would suggest following the wizard structure on kmp.jetbrains.com. It's the latest in our thinking
👍 1
e
I'm not sure if there's a "one size fits all" approach here. For example, my project currently has separate modules for the different apps (Android, ios, Desktop, Web) because all those modules do is setup the platform to call into my actual code, e.g. the Android app module sets up the
Application
and
Activity
, Web sets up the call to
CanvadBasedWindow
etc... It also allows me to have simpler Gradle files that focus on the specific platform, while having all of them in one file would be less manageable (I could make separate convention plugins to setup the specific apps, but then it's less localized). However I could see other applications benefiting from having everything in one module.