The best book to teach you how to share code across platforms using Kotlin Multiplatform. You’ll gain the foundation of creating user interfaces using native UI toolkits and then writing common code for serialization, networking and persistence. You’ll also learn how dependency injection, testing and different architectures fit in with Kotlin Multiplatform so that you build maintainable and scalable apps for the real world.
Before You Begin
This section tells you a few things you need to know before you get started, such as what you’ll need for hardware and software, where to find the project files for this book, and more.
One of the core benefits of Kotlin Multiplatform is that you can share code across native apps. You can continue to develop the UI layer using native UI toolkits like Jetpack Compose for Android and SwiftUI for iOS.
In this section, you’ll learn how to add a new Gradle module to write your business logic only once. You’ll also learn how to create the native UI for Android, iOS and desktop apps, all while sharing the common module.
Kotlin Multiplatform (KMP) is one of the latest technologies to help you share code across platforms. This chapter introduces you to KMP, how you can use it across app layers and how to set up your first KMP project.
Having reliable build tools and consistent dependency versions is crucial to getting started on a multiplatform project. This chapter will cover how you can use Gradle and its buildSrc module to provide dependencies to all modules. You'll also learn how to share business logic across target platforms using a multiplatform time zone library.
It's now possible to share the same UI code across desktop and Android applications. In this chapter, you'll learn how to develop the UI for desktop using the new Compose Multiplatform declarative library.
Section II: Kotlin Multiplatform: Intermediate
To effectively share code across apps, there are multiple things to keep in mind: access to platform-specific APIs, support for existing software engineering practices and persistence.
In this section, you’ll learn how to use Kotlin features to access platform-specific APIs in your shared module and how Kotlin Multiplatform fits in with your current architecture. You’ll also learn about dependency injection and how you can use it to test features present in your shared modules. Finally, you’ll learn how to use a common codebase to handle persistence on different platforms.
When working with KMP, you'll often need to access platform-specific APIs. In this chapter, you'll take a deeper dive into the expect/actual pattern and how you can use them to access platform-specific APIs.
Software architecture is one of the most crucial aspects that affect quality and maintainability over time. In this chapter, you'll get an overview of different architectures and how you can use one of them in your KMP application.
Dependency Injection is a technique that leads to maintainable and testable code. This chapter will provide an overview of integrating the Koin dependency injection library into a multiplatform project.
Most modern applications need to persist data across sessions. This chapter will provide an overview of data persistence in KMP. It discusses key-value saving as well as using an SQL database.
Section III: Kotlin Multiplatform: Advanced
Networking is crucial to most modern apps, and it usually involves implementing similar logic using different frameworks and languages. Under the hood, it also involves concepts like serialization and concurrency. Fortunately, Kotlin Multiplatform has dedicated libraries for each of these.
In this section, you’ll learn how to use serialization to decode JSON data to Kotlin objects. You’ll then learn how to use a common networking library that leverages this common serialization to fetch data from the internet. To make the networking performant, you’ll also learn about concurrency in Kotlin using coroutines and the considerations for different platforms. Finally, you’ll learn how to extract an existing feature to a Kotlin Multiplatform library and also different ways of publishing this library.
Melanie is a freelance editor, proofreader, and writer--and something of an indie archivist with an interest in text...
Who is this book for
This book is for mobile developers and managers who want to explore how they can use Kotlin Multiplatform in different use cases to share code across Android, iOS and desktop apps. If you want to reduce development and testing time by writing certain parts of your apps only once, this book will help.
Concepts covered in this book
Jetpack Compose Android
Dependency Injection with Koin
Persistence using SQLDelight
Concurrency using coroutines
First Edition · Android 12, iOS 15, Desktop, Kotlin 1.6.10, Android Studio Bumblebee
v1.0 · Mar 16 2022 · Carlos Mota, Saeed Taheri & Kevin D Moore