Kotlin Multiplatform for Android and iOS Apps
rockandnull.com
rockandnull.com
Kotlin is indeed popular in it's specific domain (Android & Java). But the company is keen to position it as "write once run anywhere" space with a strong focus on multiplatform development.
1. The build system provides platform specific bindings for free (huge plus compared to the hassle of writing the core in C/C++ and then hand-writing platform specific bindings)
2. Keen focus on enabling single codebase for multiple platforms.
3. The company went so far, as to build a multi-platform UI Framework (Compose Multiplatform) that directly renders to Skia and runs on all mobile/desktop platforms. And even on browsers (with wasm)
I find it odd, that such interesting a language / compiler finds little attention beyond its domain.
Is there any reasons for this that I'm missing?
I'm an iOS dev and I've been using KMM on a couple of projects for more than a year now. It's really a powerfull technology which allows teams to move faster, but there are downsides, for example lack of native Swift interop, though there are opensource tools trying to solve this [2].
[1]: https://github.com/Kotlin/kmm-production-sample/tree/master#... [2]: https://github.com/touchlab/SKIE
The other multiplatform attempts failed because they were trying to use languages that neither side wanted or knew and pretended like you could drop in a dev from a completely different field and not need to know much about the platforms. If you did know the platform you were fighting against the framework in an unfamiliar language.
That said it is definitely not there yet, but I hope they get it to a reasonable place. I've enjoyed Android development and would love to be able to more simply port over a project without a complete rewrite.
It’s a GC language, so rust/zig are not good comps. Go, Java, Scala, Server side JS/Node, or python. These are the comps.
Personally, I’ve written a number of non-trivial, server side applications in Kotlin. The extra cost of asking my colleagues to learn another language and some pain in the interop with Java has dampened adoption. It’s a shame, I find the coroutine library a joy to use, with none of the painful drawbacks of go, node, python, etc.
It has downsides to be sure but it's not as simple as evaluating it as just another option for compiling to bytecode anymore.
Such as?
No, really, I'm interested!
Learning a language isn't a huge burden. Frameworks and libraries can alleviate huge burdens. Kotlin avoids the benefits of frameworks and libraries while giving meager benefits in term of language constructs.
I wanna understand better as I do kotlin in daily basis, some with spring, some with ktor and some with android and I don't get your points.
I basically only write expect/actual implementations to talk to platform APIs, but even those, when abstracted correctly behave just like a normal API to users.
You still write the UI layer natively. IMO this is a positive not a negative unless you're working on a product that doesn't care about native UX. And if you REALLY want a shared UI layer, Compose Multiplatform seems to be right around the corner.
Compose Multiplatform requires WASM (with GC!). This is going to require a Kotlin runtime plus Skia bundled in the WASM, probably with large parts of the standard library, and draw everything to the screen with canvas. Like Flutter apps, these apps will not load fast and will probably have accessibility issues.
I’d like to see it thrive but I’m not optimistic.
What if Jetbrains decides overnight "you know what? this whole Compose Multiplatform is taking up too many of our resources, we're going to retire it at the end of this quarter"?
If you need something close to the metal, you have C and others that are multiplatform. If you want to do something slightly platform specific you loose the multiplatform claim instantly anyway.
IMHO, if you are going to do something that is not an UI to an API or a database, just do it in the native toolset for the platform so you can do it properly. Otherwise, just do a web app.
Apple's iOS API&Frameworks is quite extensive, if you are not doing just an UI then you will likely need to learn that. And for the UI? If your app is going to match the iOS conventions, do it in SwiftUI or UIKit as Apple will handle most of the stuff for you. It's probably the same for Android, no?
I wouldn't want to write the UI also in KMP, though you could do even that if you don't mind using beta software (see https://www.jetbrains.com/lp/compose-multiplatform/).
Using Flutter makes much more sense in that case as nowadays it's very mature, has a huge library and excellent developer UX.
In fairness, KMM and KMP are still in beta and the compiler has been in the process of being overhauled. That's a process that is nearly completed but it is still ongoing. Having used the new k2 compiler with kotlin-js, it's a big upgrade in terms of performance. I expect a lot of stuff to start stabilizing post Kotlin 2.0, which should be out in later winter/spring next year. 1.9.10 is the current release. 1.9.20betas are already out. There might be a .30 but the release after that is basically 2.0. 3-6 months out basically if Jetbrains sticks to their normal release schedule.
IOS support in Compose Multiplatform is alpha quality. You shouldn't use it for anything important. But when it is done, you can expect to be able to develop applications with one code base that run nicely on Android, IOS, the web, or on desktops.
Compose web is actually targeting the new wasm compiler. Which of course is also alpha. That's an interesting one because it uses the WASM standardize GC facilities. That's currently out in browsers already but hidden behind feature flags. Which are very likely to come off soonish.
Give it a year or two. Too early to write it off now when it is basically all early access and alpha/beta quality. IMHO, there is some good tech coming together there.
And that translates to Electron on the desktop environment and a webview on mobile devices I guess?
How is that better than Flutter for example? With Flutter, I am able to write once and compile to all platforms.
Kotlin multiplatform and compose multiplatform are about leveling the playing field a bit and giving developers more choices than this one size fits all straight jacket that is the "modern" web (I use the word modern loosely here).
And it allows people targeting mobile to target other platforms with their code bases. If it's valid to use the web on mobile, then why not use mobile frameworks on the web?
If anyone here has used it for that, care to share your experience?
Ecosystem is no good. Almost all Kotlin libraries assume Android and don’t work on multi platform. Common things just don’t exist.
- React Native is easy to find workers for but slow
- Kotlin is somewhat in the middle of both but has better performance
- Tauri is coming out of left field with webview2 apps but it's very early days for their mobile plans and completely unproven
Kotlin does a good job with all the compromises you have to make with cross platform but it's quite application dependent?
I think Google has a winner on their hands here if they don’t give up on it.
Maybe something like Kotlin/Compose Multiplatform can help. But, really if they made Android APIs (or React-native/Flutter/Compose) into a ISO/ECMA/ANSI whatever standard it would feel like I'm not just throwing away my time on some proprietary API that may change in a way that I have to update my app or loose my investment.
Then again my use of these things is that of a hobbyist so I have a choice in these things.
I don't know exactly if that's what stopped me or maybe I'm just just not meant for learning UI libraries of any sort as even something like Dear Imgui has been unattractive to me.
For those who discuss 'compose multiplatform' and UI sharing using KMP, it's essential to understand that KMP's primary focus is logic sharing. Sharing user interfaces is merely an additional capability it offers via Compose Multiplatform. I strongly recommend that everyone conducts further research. Comparing KMP with Flutter and React Native is like comparing apples and oranges.
> You might be able to write UI and business logic in Kotlin for your Android app, and easily port it to iOS to kick-start your app journey. When the app becomes big enough (and you choose so) you can write a native iOS UI and still share the business logic between the 2 apps.
This seems like the less common order, anecdotally.
Same goes for any other multi platform GUI.
I feel dart is further along on this.
Seems a little silky having 2 projects aimed at the same thing?