Build native apps faster and more reliably by sharing code across Android, iOS and desktop.
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.
Author(s): Kevin D. Moore; Carlos Mota; Saeed Taheri
Edition: First
Publisher: Razeware LLC
Year: 2022
Language: English
Pages: 400
What You Need
Book Source Code & Forums
Dedications
About the Team
About the Authors
About the Editors
Introduction
How to read this book
Chapter 1: Introduction
What is Kotlin Multiplatform?
Setting up your environment
Creating your first project
Key points
Where to go from here?
Chapter 2: Getting Started
Getting to know Gradle
BuildSrc
Shared build file
Android build file
Find Time
Business logic
Challenge
Key points
Where to go from here?
Chapter 3: Developing UI: Android Jetpack Compose
UI frameworks
Jetpack Compose
Time finder
Time Zone screen
Find Meeting Time screen
Key points
Where to go from here?
Chapter 4: Developing UI: iOS SwiftUI
Getting to know SwiftUI
Key points
Where to go from here?
Chapter 5: Developing UI: Compose Multiplatform
Getting to know Compose Multiplatform
Creating a desktop app
Shared UI
Key points
Where to go from here?
Chapter 6: Connect to Platform-Specific API
Reusing code between platforms
Say hello to Organize
Updating the Platform class
Updating the UI
Challenge
Key points
Chapter 7: App Architecture
Design patterns
Sharing business logic
Creating Reminders section
Sharing tests and UI
Challenge
Key points
Chapter 8: Testing
Setting up the dependencies
Writing tests for RemindersViewModel
Writing tests for Platform
UI tests
Challenge
Key points
Where to go from here?
Chapter 9: Dependency Injection
Advantages of dependency injection
Automated DI vs. manual DI
Setting up Koin
Using Koin in each platform
Updating AboutViewModel
Testing
Key points
Where to go from here?
Chapter 10: Data Persistence
Key-Value storage
Database
Challenge
Key points
Where to go from here?
Chapter 11: Serialization
The need for serialization
Project overview
Application features
Adding serialization to your Gradle configuration
Different serialization formats
Creating a custom serializer
Serializing/deserializing new data
Serializable vs. Parcelable
Implementing Parcelize in KMP
Testing
Challenges
Key points
Where to go from here?
Chapter 12: Networking
The need for a common networking library
Using Ktor
Adding Ktor
Connecting to the API with Ktor
Plugins
Retrieving content
Adding headers to your request
Uploading files
Testing
Challenge
Challenge: Send your package name in a request header
Key points
Where to go from here?
Chapter 13: Concurrency
The need for structured concurrency
Understanding kotlinx.coroutines
Structured concurrency in iOS
Using kotlinx.coroutines
Working with kotlinx.coroutines
New Kotlin/Native memory model
Challenge
Key points
Where to go from here?
Chapter 14: Creating Your KMP Library
Migrating an existing feature to Multiplatform
Publishing your KMP library
Challenges
Key points
Where to go from here?
Chapter 15: Conclusion
Appendix A: Kotlin: A Primer for Swift Developers
Kotlin and Swift: Comparing both languages
Kotlin and Swift syntax table
Where to go from here?
Appendix B: Debugging Your Shared Code From Xcode
Debugging the shared module
Where to go from here?
Appendix C: Sharing Your Compose UI Between Android & Desktop
Updating your project structure
Sharing your UI code
Migrating Your Android UI code to multiplatform
Compose Multiplatform
Using third-party libraries
Handling resources
What’s missing?
Where to go from here?