Thread
#multiplatform
    Sam Garfinkel

    Sam Garfinkel

    2 years ago
    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
    expect
    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?
    c

    Casey Brooks

    2 years ago
    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

    Sam Garfinkel

    2 years ago
    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 🙂
    russhwolf

    russhwolf

    2 years ago
    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
    kpgalligan

    kpgalligan

    2 years ago
    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

    Sam Garfinkel

    2 years ago
    I didn’t have a particular target in mind, was more curious about the process.