We've now seen several examples of how to write and share common Kotlin code. However, if you're building a real application today, you likely don't want to build everything from scratch. You're probably going to need things such as networking, serialization, settings, and dependency injection. You might want to leverage reactive programming paradigms, or use common tools such as Firebase. For these situations, it's of great benefit to have third-party libraries available that you can rely on for multiplatform implementations.
As of today, the third-party library ecosystem for Kotlin multiplatform is pretty limited. Because the technology is relatively new, there aren't many options out there yet. However, there are a few libraries available that may be quite helpful:
- ktor—a Kotlin-based framework for asynchronous servers and clients that can be leveraged for multiplatform networking.
- kodein—a dependency injection framework.
- sqldelight—provides APIs for working with SQLite across JVM, Android, and iOS.
- multiplatform-settings—a multiplatform implementation of simple key/value pairs.
- kotlinx.coroutines—coroutines are supported in multiplatform projects and can be used in your common code to solve structured concurrency problems.
- kotlinx.coroutines.flow—provides, cold, asynchronous data streams similar to what you might be familiar with from RxJava. When combined with coroutine-based channels, you can achieve highly reactive code within Kotlin.
- Reaktive—a Kotlin multiplatform implementation of reactive extensions.
While this is a small set of well established libraries, many more libraries are in active development, including implementations for Firebase, logging, and I/O. As more and more developers begin to work with Kotlin multiplatform, the developer ecosystem should continue to expand, making it easier to find existing tools and libraries.
While quite exciting in its current state, like everything, Kotlin multiplatform has some drawbacks. In the next section, we will study a few limitations of the Kotlin multiplatform approach to cross-platform code.