https://kotlinlang.org logo
t

Tony Kazanjian

02/07/2022, 10:28 PM
Hey KMP people! Just have a question I'd like to ask the community about what it was like getting started writing Kotlin Multiplatform apps from a primarily Kotlin and/or Android background. What were the gotchas, pain points, or assumptions you had to overcome when you first got started?
l

Landry Norris

02/07/2022, 10:46 PM
The hardest one for me was freezing on iOS builds. I would build, debug, and test on Android until I was happy with the app, then open an iOS simulator and… InvalidMutabilityException. The new memory model seems to work great so far, so hopefully this won’t be a problem in the future.
🙏 1
👍 1
r

Russell Stewart

02/08/2022, 2:43 AM
+1 on that. Learning to think in Immutable took a little doing, but once I got the hang of it it wasn't that hard. In some ways, I would even say it enforces good practices. The other big cognitive shift for me was learning to separate Kotlin from Kotlin JVM. When you're writing Kotlin code on Android you're writing against the JVM, which means you have access to all of the standard JVM libraries - from simple things like String formatting to more sophisticated tools like Retrofit. When you're in Kotlin Native (i.e., writing for the common module in KMM), all of that is gone, and K/N doesn't have anywhere near as many or as mature support libraries as Java does, because it's so much newer. The language may be familiar, but the environment is very different. Many of the things you have learned to take for granted as an Android developer are no longer there, and you have to either find replacements for them (which means hunting down and evaluating different libraries and learning new APIs), or use
expect/actual
to implement them on each specific platform.
3
g

Grégory Lureau

02/08/2022, 8:17 AM
+1 o Kotlin vs Kotlin JVM. Also I use JS/Typescript export, and having a nice API from Kotlin to Natives and typescript was a big pain point, mainly because you have to level down (like avoid using Long for example) or find tricks (like generating facade dedicated to a specific platform). Also concepts like "File" or multithreading is quite different on a web browser, (same for Channel/Flow not exportable in JS), and it's not always obvious how you want to deal with those concepts in a "generic"/"multiplatform" way. Tech is still young, so there is not a lot of example or a consensus on how to do everything (compared to Android).
r

Russell Stewart

02/08/2022, 3:14 PM
Yeah, I haven't even touched Kotlin JS yet. I'm sure that's a whole other can of worms.
l

Landry Norris

02/08/2022, 3:16 PM
I think commonMain used to require you to write compatible with all targets, even those you weren't using. I always had to make basically a 'anything but JS' source set.
m

Michael Paus

02/08/2022, 8:25 PM
r

Russell Stewart

02/08/2022, 8:30 PM
Yeah, I saw that the other day. Definitely good to know.
t

Tony Kazanjian

02/09/2022, 7:36 PM
Thank you for the responses everyone! I can definitely relate to the mindset shift coming in as an Android developer and realizing Kotlin/JVM != Kotlin
2 Views