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

Mastering Cross-Platform Development with Kotli...

Mastering Cross-Platform Development with Kotlin Multiplatform Mobile

Su Thwe Thwe Tun

July 29, 2024
Tweet

More Decks by Su Thwe Thwe Tun

Other Decks in Technology

Transcript

  1. I’m passionate about building mobile apps to achieve easier and

    better lifestyles in our everyday lives. I have been working as a mobile developer for 10 years with Android and Flutter. SU THWE THWE TUN MOBILE APPLICATION DEVELOPER @USA
  2. Introduction to KMM Kotlin Multiplatform Mobile (KMM) is an SDK

    by JetBrains. Use a single codebase for native iOS and Android applications. It can share common business logic and code. Write platform-specific code when necessary. WHAT IS KMM?
  3. Advantages of KMM KMM only shares business logic. Flutter and

    React Native use a single codebase for both UI and logic COMPARISON WITH OTHER CROSS-PLATFORM FRAMEWORKS KMM enhances development speed by sharing code between iOS and Android. BENEFITS
  4. INSTALL KMM PLUGIN Install Android Studio. 1. Open Android Studio.

    2. Go to Preferences (or Settings on Windows/Linux). 3. Navigate to Plugins and search for "Kotlin Multiplatform Mobile". 4. Install the plugin and restart Android Studio. 5.
  5. Setting up a KMM project using Android Studio. 1. Open

    Android Studio. 2. Click on New Project. 3. Select Kotlin Multiplatform App from the project templates. 4. Follow the wizard to set up your project. 5. SETTING UP A KMM PROJECT IN ANDROID STUDIO.
  6. Architecture Overviews shared: Contains the shared code. commonMain: Shared code

    for both platforms. commonTest: Shared test code. androidMain: Android-specific code. iosMain: iOS-specific code. androidApp: Contains the Android-specific application code. iosApp: Contains the iOS-specific application code.
  7. “expect” keyword: Declared in shared module to be implemented on

    each platform. USING “EXPECT” AND “ACTUAL” “actual” keyword: Declared in the Android and iOS modules to provide the actual implementations of the “expect”.
  8. In these examples, the “actual” keyword is used to provide

    platform-specific implementations of the getPlatformName() method.
  9. KTOR It is for servers and clients in connected systems

    using Kotlin. It allows to sharing of networking code between Android and iOS. KTOR IS A FRAMEWORK.
  10. Setting Up Ktor in Shared Module Open shared/build.gradle.kts and add

    the necessary Ktor dependencies. ADD KTOR DEPENDENCIES
  11. Calling Native APIs from Shared Code Using expect and actual

    keywords Define platform-agnostic API in shared code Provide platform-specific implementations
  12. Keep platform-specific code minimal. BEST PRACTICES Use shared code for

    business logic. Ensure platform-specific implementations are isolated.
  13. Unit tests are written in the commonTest which can be

    executed on both Android and iOS. Writing Unit Tests for Shared Code
  14. Open Android Studio. 1. Navigate to the commonTest directory. 2.

    Right-click on the test file (CalculatorTest.kt). 3. Select "Run 'CalculatorTest'". 4. Running Tests on Android Studio
  15. Open a terminal. 1. Navigate to your project directory. 2.

    Execute this command. 3. Running Tests on iOS ./gradlew iosTest JUnit is used for writing and running tests on the JVM. It can be executed directly from Android Studio or via the command line. Running JUnit Tests ./gradlew test
  16. SUMMARY Run tests using Android Studio for Android and command

    line for iOS. Use kotlin.test for cross-platform testing. Use JUnit for JVM-specific testing. Tools and Frameworks for Testing:
  17. Overview of IDE Support Full support for Kotlin Multiplatform projects.

    Integrated tools for coding, building, and debugging. PRIMARY IDE: ANDROID STUDIO IntelliJ IDEA Xcode (for iOS-specific development) OTHER SUPPORTED IDES
  18. Debugging Techniques Use Android Studio’s built-in debugger for Android Use

    Xcode for debugging iOS code DEBUGGING Print statements and logging for shared code Using conditional breakpoints CROSS-PLATFORM DEBUGGING
  19. Case Study: Netflix - Mobile Studio Company: Netflix Project: Mobile

    Studio Objective: Build a mobile application for internal use by Netflix’s creative teams. Overview :
  20. Case Study: Netflix - Mobile Studio Frequent updates and features

    required for both iOS and Android. High costs and time consumption due to maintaining separate codebases. Difficulty in synchronizing new features and bug fixes across platforms. Challenges :
  21. Case Study: Netflix - Mobile Studio Implemented KMM to share

    common business logic and core functionalities. Utilized Kotlin for shared code and native Swift/Java for platform-specific implementations. Focused on sharing models, data handling, and business logic while keeping UI native. Solution :
  22. Case Study: Netflix - Mobile Studio Networking: Used Ktor for

    making network requests. Persistence: Implemented SQLDelight for shared database operations. ViewModels: Shared ViewModel logic using KMM to manage UI-related data. Technical Details :
  23. Case Study: Netflix - Mobile Studio Efficiency: Increased development efficiency

    by sharing up to 80% of the codebase. Speed: Faster feature rollouts and synchronized updates across both platforms. Consistency: Improved consistency in features and performance across platforms. Benefits :
  24. Case Study: Netflix - Mobile Studio Results : Increased Efficiency

    Shared codebase reduces duplication of effort Consistent User Experience Unified business logic across platforms ensures consistency Cost Savings Reduced development and maintenance costs
  25. Overview of the KMM Community Active Community Support Forums, Slack

    channels, and social media groups Official Documentation and Tutorials Comprehensive guides on the JetBrains website
  26. POPULAR LIBRARIES AND TOOLS Ktor For network operations SQLDelight Type-safe

    SQL for Kotlin Multiplatform Multiplatform Settings For managing application settings across platforms
  27. GitHub repositories for community- driven projects Getting involve in reporting

    issues, submitting PRs, writing documentation Contribution Opportunities
  28. IMPACT ON MOBILE DEVELOPMENT Unified Development Process Single codebase for

    business logic across platforms Cost and Time Efficiency Reduced development time and costs Evolving Best Practices New design patterns and practices for cross-platform development
  29. Conclusion Use expect and actual for platform-specific implementations Keep platform-specific

    code minimal and isolated Share business logic across platforms KEY TAKEAWAY