# multiplatform

Sam Garfinkel

04/23/2020, 4:37 PM
What’s the best approach to making an existing JVM library (dependency-free) multiplatform compatible? I see two options, reimplement all Java in Kotlin as a common module, or implement just the API with
in the common and delegate to the Java library on the JVM, and other similar libraries on their respective platforms (like a swift library with the same capability on Mac/iOS, etc.). Is one better than the other?

Casey Brooks

04/23/2020, 4:41 PM
I think you’d be better in the long-run to reimplement it in Kotlin. It will likely be more stable and much easier to maintain, at the cost of higher initial investment. Delegating to platform libraries is certainly an option, but then you’re left dealing with more platform-specific bugs and functionality that isn’t quite the same between the different supported platforms. And depending on how big the library is, it might not even be faster or easier to go that route, because of all the overhead of finding and learning the platform libraries

Sam Garfinkel

04/23/2020, 4:49 PM
Yeah that’s what I was leaning towards. Of course if the library has dependencies that approach doesn’t work--but the more dependency-free libraries that can be reimplemented in pure kotlin, the more dependency-requiring libraries can also be reimplemented in kotlin 🙂


04/23/2020, 4:53 PM
Even if you have dependencies, you might be able to abstract them out and do a lot of logic in common. Ideally you just need to implement a subset of internals per-platform. The ease of doing that though depends a lot on how the library is architected and what functionality it provides


04/23/2020, 4:57 PM
Agree with Russell. It takes some practice, but you kind of get a feel for splitting out common code and delegating to platform specifics when needed. If you had something specific in mind, might be easier to discuss.

Sam Garfinkel

04/23/2020, 9:26 PM
I didn’t have a particular target in mind, was more curious about the process.