Kotlin Multiplatform

3295d80faee461db1093982361256fe4?s=47 Panini
December 20, 2018

Kotlin Multiplatform

3295d80faee461db1093982361256fe4?s=128

Panini

December 20, 2018
Tweet

Transcript

  1. Kotlin Multiplatform 集まれもうやんカレーとKotlin好き!Kotlin愛好会 vol6

  2. About Me • Matthew Vern / Panini • Twitter: @callipan

    Github: panpanini • Mercari, Inc • Android Engineer (US) • Kotlin可愛い
  3. Summary • I made a Kotlin Multiplatform project! • It

    has an Android and iOS app both backed by a common library
  4. Kotlin Multiplatform

  5. Kotlin Multiplatform • https://speakerdeck.com/panini/kotlin-multi-platform • This time I will actually

    talk about Kotlin Multiplatform
  6. Kotlin Multiplatform • https://kotlinlang.org/docs/reference/multiplatform.html • 1 codebase, multiple platforms ◦

    Android ◦ iOS ◦ JS ◦ (JVM)
  7. Kotlin Multiplatform - requirements • Multiplatform code must be 100%

    pure Kotlin • Platform specific code must be referenced using `expect` and `actual`
  8. Kotlin Multiplatform - tutorial • https://kotlinlang.org/docs/tutorials/native/mpp-ios-android.html • Explains how to

    use `expect` and `actual` mechanism expect fun platformName(): String fun createApplicationScreenMessage() : String { return "Kotlin Rocks on ${platformName()}" }
  9. :thinking:

  10. Kotlin Multiplatform - tutorial v2.0 • I want a realistic

    sample project, that reflects real world usage • It should perform network operations • UI should be managed by each platform, so only logic should be shared
  11. Lets build!

  12. Lets build! • I wrote some details in this blog,

    please check it! • https://tech.mercari.com/entry/2018/12/18/114010 • I want to build this architecture
  13. Lets build! • First, lets build http client • Because

    I’m normally an Android Engineer, lets use Retrofit • https://square.github.io/retrofit/ • It lets us make network calls just by creating an interface
  14. None
  15. Kotlin Multiplatform - requirements • Multiplatform code must be 100%

    pure Kotlin • Platform specific code must be referenced using `expect` and `actual`
  16. None
  17. None
  18. None
  19. Ktor • https://ktor.io • Kotlin http server • Kotlin http

    client
  20. Ktor • https://ktor.io • Kotlin http server • Kotlin http

    client • Multiplatform support
  21. Lets build!!!!

  22. Service.kt

  23. ViewModel.kt

  24. Observable.kt

  25. Lets build iOS!!!!

  26. Observable.kt

  27. Observable.kt

  28. Lets open Xcode!!!!

  29. Xcode………..

  30. SplatMaps.xcproject

  31. ViewController.swift

  32. None
  33. Lets build Android!!!!

  34. SplatoonCoroutine.idea

  35. MatchFragment.kt

  36. None
  37. Summary • I made a Kotlin Multiplatform project! • It

    has an Android and iOS app both backed by a common library • Http client is not as easy to use as Retrofit • return KotlinUnit() is ダサイ... • Kotlin works anywhere and that makes it 可愛い • https://github.com/panpanini/SplatMaps-Multiplatform
  38. Have a nice Kotlin!