Anyone have a demo or some guidance on how to comb...
# multiplatform
Anyone have a demo or some guidance on how to combine server and mobile app code into one project? I was hoping to share data models between server and mobile apps, but have app-related view models just compile with the Android an iOS versions. Basically, I want to share code between two parts: a JVM server app and a mobile app, where the mobile app has its own shared code and Android- and iOS-specific Kotlin code.
I'm not sure exactly what you're looking for, but here's a demo I wrote for a few colleagues of mine:
It's a bit of setup to learn how to create Gradle modules, but once you get the hang of it, you can create essentially any structure you want
I usually go with:
Copy code
core/ ← domain objects, shared between client and server

app/ ← the UI
app-android/ ← Android-specific UI stuff

http-common/ ← DTOs for the HTTP API
http-server/ ← server-side route declarations
http-client/ ← client-side route calls

backend ← just the main method that instantiates everything server-side
Thanks. I think the repo might be private, because I'm getting a 404 on your demo. Luckily, I think I found a repository that shows
code sharing as well as code shared between client and server. Just had to look a little harder.
I think I just need to practice and learn gradle more thoroughly
Ah, sorry 😐 This repository is public, but it's a full project, not just a demo. Although the project structure is somewhat regular, the actual code is quite unusual, so keep that in mind you want to take inspiration.
This is super interesting. Thank you!
The repository you found looks good, but I'm not a fan that it uses the domain objects directly in the API instead of using DTOs.
I prefer having another shared module for DTOs instead of having them in
. But the Gradle setup looks good, if that's what you're looking for
(it's written in Groovy syntax, and not Kotlin though)
I will keep the idea of separating DTOs in mind, thanks!
hi @Evan Foster you need to do multi-module multiplatfom project here is a project start you can use this will give you a kmp sdk setup , but you can teak it for kmm project needed modules : •
<------ this is shared by backend/frontend
Thanks! I actually managed to get the whole thing set up, at least just with some simple greeting example code. My structure looks like this •
<— JVM Server App •
<— Shared by all •
<— Shared by iOS and Android
It took a while to figure it all out, but I successfully ran all three apps, though they’re just simple things
one more, mine also combines all targets in 1 repo: