Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Challenges in Kotlin Multiplatform Mobile for ...

Challenges in Kotlin Multiplatform Mobile for Mobile Developer

KMM is the future of mobile apps and hopefully, a replacement for flutter/react native apps. As being an advantage of code reusability, kotlin plays a pivotal role that KMM also took this benefit by writing kotlin shared code that would work as a single codebase in building awesome iOS and Android apps. As an Android dev, you would face a few challenges while writing KMM app because of having a shared codebase between iOS and Android app and developers also have to use those items that would be supported in both OS.

So in this talk, I have discussed restrictions, limitations, and challenges we have to keep in mind while writing KMM apps, and as the kotlin syntax is also much similar to iOS syntax that it would also help iOS dev to work on KMM apps.

Ali Azaz Alam

July 17, 2023
Tweet

More Decks by Ali Azaz Alam

Other Decks in Programming

Transcript

  1. Challenges in Kotlin Multiplatform Mobile Discuss challenges that would face

    by an android dev when building an iOS/Android App. Mostly Photo in this slide are by Unknown Author is licensed under CC BY-NC
  2. Android App Development platforms • Traditionally, Android app development would

    be done through native languages like Java | Kotlin and UI through XML & Jetpack Compose. • Even though, there are also other ways to achieve an app using cost effective and awesome UI.
  3. iOS App Development platforms • iOS application development is a

    little bit restrictive due to its IDE i.e Xcode. • iOS Apps written traditionally in Objective-C and now dev adopts SwiftUI. • Swift awesome UI and backward code support through Objective-C.
  4. KMM vs KMP KMM – Deals with mobile platform. KMP

    - Deals for all platform, including iOS, Android, and Web
  5. KMM •Create cross platform app with native code. •Adopted by

    world’s leading companies, including Philips, Netflix, Leroy Merlin, and VMWare. •Single codebase for the application logic. •In alpha right now
  6. CocoaPods Dependency • CocoaPods is a dependency manager for Swift

    and Objective-C Cocoa projects. • It has over 90 thousand libraries and is used in over 3 million apps. • CocoaPods can help you scale your projects elegantly.
  7. Actual / Expect – under the hood •Implementation that all

    OS would do it by themselves. •It is like a lateint modifier, means promise that I would do expect implementation at all OS side. • Expect is like an interface in Kotlin and protocol in Swift.
  8. Ktor - Network •In android - use Retrofit/Volley for network

    calls. •In iOS – use AlamoFire/AFNetworking for network calls. •Because these Api’s are not available in KMM we have to target Ktor for it. •Kotlin Serialization – works with Ktor.
  9. Ktor – Challenge for iOS •Coroutine is bundled with Ktor

    to do asynchronous calls. •With coroutine run the app on Main | IO thread. •iOS doesn’t any concept of coroutine or suspend function. •Use callback to deal with coroutine.
  10. Storage •Local Caching is also required when dealing with app

    that requires data to store for future use, like token, login info, and so on. •In Android – Use Room and In iOS – Core Data, but no one is available in KMM, therefore here is SqlDelight. •There is one storage Api that is now available in KMM i.e Realm.
  11. SQL-Delight •Type safe •Work with SQLite, MySql, and PostGresSQL. •It

    work as a glue between database scheme that you defined and platform specific need.
  12. Dependency Injection •One object supplies the dependencies of another object.

    •In Android – Dagger & Hilt and in iOS – Swinject & Manual. •In KMM these of them aren’t available but we have Koin that is compatible with KMP.
  13. Koin •A lightweight dependency injection framework. •Declarative library, DSL. •Use

    modules for declare dependencies. •Use single{..}, singleOf{..} & factory{..}, factoryOf{..}
  14. Logging Napier logging ./Shared/AndroidMain & iOS Main – Initialization Calling:

    Kermit logging No initialization required - Implementation Calling:
  15. Moko-Resources •KMM library to share resources between both OS. •Resources

    includes Strings, Plurals, Images, Fonts, Colors, and Files.
  16. Moko-MVVM • ViewModel - store and manage UI-related data. Interop

    with Android Architecture Components - on Android it's precisely androidx.lifecycle.ViewModel; • LiveData, MutableLiveData, MediatorLiveData - lifecycle-aware reactive data holders • EventsDispatcher - dispatch events from ViewModel to View with automatic lifecycle control and explicit interface of required events; • DataBinding, ViewBinding, Jetpack Compose, SwiftUI support - integrate to Android & iOS app with commonly used tools; • All Kotlin targets support - core, flow and livedata modules support all Kotlin targets.
  17. References • Kotlin multiplatform by tutorials by the raywenderlich tutorial

    team Kevin D.Moore, Carlos Mota & Saeed Taheri • https://github.com/icerockdev • https://github.com/AAkira/Kotlin-Multiplatform-Libraries • https://student.cs.uwaterloo.ca/~cs398/1-syllabus/2-weekly-schedule/lectures/13-kotlin-multiplatform-slides.pdf • https://mmmnnnmmm.com/kotlin-kmm-swift-ios-stateflow.html • https://kotlinlang.org/docs/native-objc-interop.html#mappings • https://ktor.io/docs/getting-started-ktor-client-multiplatform-mobile.html