Simplifying Application Development with Kotlin Multiplatform Mobile

Book description

Explore the new Kotlin Multiplatform to build native apps for Android and iOS while sharing business logic between apps

Key Features

  • Improve app development speed dramatically by writing the business logic in Kotlin
  • Implement a native user interface and work with platform-specific APIs
  • Leverage Kotlin Multiplatform Mobile's code-sharing capabilities for your projects

Book Description

Sharing code between platforms can help developers gain a competitive edge, and Kotlin Multiplatform Mobile (KMM) offers a sensible way to do it. KMM helps mobile teams share code between Android and iOS in a flexible way, leaving room for native development.

The book begins by helping you to gain a clear understanding of the Kotlin Multiplatform approach, how it works, and how it is different from cross-platform technologies, such as React Native and Flutter, and code sharing options, such as C++. You'll then see how your team can use this software development kit (SDK) to build native applications more effectively by learning timeless concepts and working through practical examples. As you advance, you'll get to grips with the core concepts, understand why UI sharing fails, and get hands-on with developing a small KMM application. Finally, you'll discover expert tips and best practices, along with production- and adoption-related questions, that will help you take the next step in your project and career.

By the end of this Kotlin book, you'll have gained a solid understanding of the capabilities of KMM and be able to share code between Android and iOS flexibly.

What you will learn

  • Get acquainted with the multiplatform approach and KMM's competitive edge
  • Understand how Kotlin Multiplatform works under the hood
  • Get up and running with the Kotlin language quickly in the context of Swift
  • Find out how to share code between Android and iOS
  • Explore tips and best practices in KMM to increase app development efficiency
  • Discover adoption tips to integrate KMM into existing or new production apps

Who this book is for

This book is for native Android and iOS developers who want to build high-quality apps using an efficient development process. Knowledge of the framework and the languages used is necessary, that is, Android with Java or Kotlin and iOS with Objective-C or Swift. For Swift developers, the book assumes no knowledge of Kotlin as this will be covered in the context of Swift.

Table of contents

  1. Simplifying Application Development with Kotlin Multiplatform Mobile
  2. Contributors
  3. About the author
  4. About the reviewers
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
    4. Download the example code files
    5. Download the color images
    6. Conventions used
    7. Get in touch
    8. Share Your Thoughts
  6. Section 1 - Getting Started with Multiplatform Mobile Development Using Kotlin
  7. Chapter 1: The Battle Between Native, Cross-Platform, and Multiplatform
    1. Understanding the compounding costs of native development
      1. The cost of native app development
      2. Synchronization
    2. Exploring the pitfalls of cross-platform solutions
      1. Assumed cross-platform development costs
      2. Actual cross-platform technology costs
    3. Adopting a multiplatform approach
      1. The multiplatform approach
      2. How KMP works
      3. Platform abstractions (expect-actual)
      4. The different use cases for KMP
      5. KMM cost implications
    4. Summary
  8. Chapter 2: Exploring the Three Compilers of Kotlin Multiplatform
    1. Kotlin compilers in general
    2. The Kotlin/JVM compiler
      1. How it works
      2. Executing Java code on Android
    3. The Kotlin/Native compiler
      1. How it works
      2. Interoperability on iOS
      3. The concurrency model
      4. Annotation processing
      5. Intermediate source sets and the Commonizer
    4. The Kotlin/JS compiler
      1. How it works
    5. Summary
  9. Chapter 3: Introducing Kotlin for Swift Developers
    1. Technical requirements
    2. Introducing Gradle
      1. Structure of Gradle
    3. Exploring Kotlin's core features
      1. Null safety
      2. Data classes
      3. Extensions
      4. Functional programming features
      5. Objects
      6. COW in Kotlin
    4. Understanding Kotlin coroutines
      1. Suspend functions
      2. CoroutineScope
      3. Executing coroutines
      4. Switching threads
      5. Streams in Kotlin
    5. Summary
  10. Section 2 - Code Sharing between Android and iOS
  11. Chapter 4: Introducing the KMM Learning Project
    1. Technical requirements
    2. Getting to know our project – Dogify
    3. Exploring prerequisites
      1. Skill requirements
      2. Required tools
    4. Understanding the technical decisions
      1. Architecture
      2. The shared code
      3. Library choices
    5. Summary
  12. Chapter 5: Writing Shared Code
    1. Technical requirements
    2. Initial project setup
      1. Project structure
    3. Fetching data from the Dog API
    4. Persisting data in a local database
      1. Exploring how to set up SQLDelight in a multiplatform module
      2. Implementing the BreedsLocalSource
      3. Connecting our database to the rest of the components
    5. Summary
  13. Chapter 6: Writing the Android Consumer App
    1. Technical requirements
    2. Setting up the Android module
      1. Enabling Jetpack Compose
      2. Adding the necessary dependencies
    3. Tying the Android app to the shared code
    4. Implementing the UI on Android
    5. Summary
  14. Chapter 7: Writing an iOS Consumer App
    1. Technical requirements
    2. Setting up the iOS app
    3. Tying the iOS app together with the shared code
    4. Implementing the UI on iOS
    5. Summary
  15. Section 3 - Supercharging Yourself for the Next Steps
  16. Chapter 8: Exploring Tips and Best Practices
    1. Technical requirements
    2. Testing shared code
    3. Architectural decisions
      1. Interacting with coroutines
      2. Interacting with data transfer objects (DTOs)
      3. Interacting with shared code
    4. Managing concurrency
      1. New memory manager
    5. App size best practices
    6. Summary
  17. Chapter 9: Integrating KMM into Existing Android and iOS Apps
    1. Deciding on a mono repository or a shared library
      1. Mono repository
      2. Multiple repositories
      3. Conclusion
    2. Exploring team structure and tooling
      1. Team structure
      2. Tooling
    3. Learning some adoption tips
    4. Summary
  18. Chapter 10: Summary and Your Next Steps
    1. Recapitulating what you have learned
    2. Managing your KMP expectations
      1. Will it change the mobile development landscape?
      2. Kotlin/Native's direct interoperability with Swift
      3. Shared UI
    3. Learning resources
    4. Summary
    5. Why subscribe?
  19. Other Books You May Enjoy
    1. Packt is searching for authors like you
    2. Share Your Thoughts

Product information

  • Title: Simplifying Application Development with Kotlin Multiplatform Mobile
  • Author(s): Róbert Nagy
  • Release date: March 2022
  • Publisher(s): Packt Publishing
  • ISBN: 9781801812580