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

Building Multiplatform projects with Kotlin (TechTrain 2018)

Building Multiplatform projects with Kotlin (TechTrain 2018)

Kotlin was presented as a better Java and eventually it could not skip the Write Once Run Everywhere concept, but did this in its own way. The other day we got an ability to build multiplatform applications in Kotlin - it doesn't try to make us write everything under JVM and run the result on different platforms using virtual machine. On the contrary, our code will be compiled for each platform separately and it's not advised to unite platform-specific functionality in any way. But our business logic, on the other hand, is the right thing to be shared and written only once.

In this talk we'll explore Kotlin's concept of multiplatform projects and dissect its features using an example of Android application and browser extension with common code.

Video: https://youtu.be/MWV5TS2gNzU

Sergey Ryabov

September 01, 2018
Tweet

More Decks by Sergey Ryabov

Other Decks in Programming

Transcript

  1. Client Backend Models Business Logic Presenters Views Android Client Backend

    Models Business Logic Presenters Views iOS Client Backend Models Business Logic Presenters Views Web Models Business Logic Backend
  2. Client Backend Models Business Logic Presenters Views Android Client Backend

    Business Logic Presenters Views iOS Client Backend Business Logic Presenters Views Web Business Logic Backend
  3. Client Backend Models Business Logic Presenters Views Android Client Backend

    Presenters Views iOS Client Backend Presenters Views Web Business Logic Backend
  4. Client Backend Models Business Logic Presenters Views Android Client Backend

    Views iOS Client Backend Views Web Business Logic Backend
  5. • C++ • J2ObjC + GWT • Xamarin • ReactNative

    / Flutter WHAT DO WE ALREADY HAVE FOR THAT?
  6. • Access to native APIs • Latest SDK version support

    • Modern dev stack MAJOR PROBLEMS
  7. • Access to native APIs • Latest SDK version support

    • Modern dev stack • Executable size MAJOR PROBLEMS
  8. Feb 2016 - Kotlin 1.0: production JVM, experimental JS Mar

    2017 - Kotlin 1.1: production JS WHY KOTLIN?
  9. Feb 2016 - Kotlin 1.0: production JVM, experimental JS Mar

    2017 - Kotlin 1.1: production JS Apr 2017 - Kotlin Native Tech Preview WHY KOTLIN?
  10. Feb 2016 - Kotlin 1.0: production JVM, experimental JS Mar

    2017 - Kotlin 1.1: production JS Apr 2017 - Kotlin Native Tech Preview Nov 2017 - Kotlin Native 0.4: iOS support WHY KOTLIN?
  11. Feb 2016 - Kotlin 1.0: production JVM, experimental JS Mar

    2017 - Kotlin 1.1: production JS Apr 2017 - Kotlin Native Tech Preview Nov 2017 - Kotlin Native 0.4: iOS support Nov 2017 - Kotlin 1.2: Multiplatform projects, JVM/JS support WHY KOTLIN?
  12. Feb 2016 - Kotlin 1.0: production JVM, experimental JS Mar

    2017 - Kotlin 1.1: production JS Apr 2017 - Kotlin Native Tech Preview Nov 2017 - Kotlin Native 0.4: iOS support Nov 2017 - Kotlin 1.2: Multiplatform projects, JVM/JS support Feb 2018 - Kotlin Native 0.6: Multiplatform support WHY KOTLIN?
  13. Feb 2016 - Kotlin 1.0: production JVM, experimental JS Mar

    2017 - Kotlin 1.1: production JS Apr 2017 - Kotlin Native Tech Preview Nov 2017 - Kotlin Native 0.4: iOS support Nov 2017 - Kotlin 1.2: Multiplatform projects, JVM/JS support Feb 2018 - Kotlin Native 0.6: Multiplatform support + transparent ObjC/Kotlin collection types interop WHY KOTLIN?
  14. Feb 2016 - Kotlin 1.0: production JVM, experimental JS Mar

    2017 - Kotlin 1.1: production JS Apr 2017 - Kotlin Native Tech Preview Nov 2017 - Kotlin Native 0.4: iOS support Nov 2017 - Kotlin 1.2: Multiplatform projects, JVM/JS support Feb 2018 - Kotlin Native 0.6: Multiplatform support + transparent ObjC/Kotlin collection types interop Jul 2018 - Kotlin Native 0.8: kotlin-stdlib sync with JVM/JS WHY KOTLIN?
  15. WHY KOTLIN IS BETTER? • Access to native APIs •

    Latest SDK version support • Modern dev stack
  16. WHY KOTLIN IS BETTER? • Access to native APIs •

    Latest SDK version support • Modern dev stack • Executable size
  17. • Gradle multimodule projects • Common • Platform • Regular


    • Multiplatform headers & implementations HOW DOES IT WORK IN KOTLIN?
  18. • Gradle multimodule projects • Common • Platform • Regular


    • Multiplatform headers & implementations • expect & actual HOW DOES IT WORK IN KOTLIN?
  19. Models common common-client Presenters Business Logic View Interfaces Repo Interfaces

    JS Models common-js JVM Models common-jvm Repository Repository Views Views Views
  20. Models common common-client Presenters Business Logic View Interfaces Repo Interfaces

    Repository Views client-js JS Models common-js JVM Models common-jvm Repository Views client-android Views
  21. Models common common-client Presenters Business Logic View Interfaces Repo Interfaces

    Repository Views client-js Repository client-jvm JS Models common-js JVM Models common-jvm Views client-android Views client-desktop
  22. Models common common-client Presenters Business Logic View Interfaces Repo Interfaces

    Repository Views client-js Repository client-jvm JS Models common-js JVM Models common-jvm backend Views client-android Views client-desktop
  23. • Drawbacks of the concept • Lots of manual work

    for module configuration (KT-23930) CAVEATS
  24. • Drawbacks of the concept • Lots of manual work

    for module configuration (KT-23930) • Several platform codebases can’t sit in one module (different SourceSets )
 CAVEATS
  25. • Drawbacks of the concept • Lots of manual work

    for module configuration (KT-23930) • Several platform codebases can’t sit in one module (different SourceSets )
 • Every platform has its own problems CAVEATS
  26. • Drawbacks of the concept • Lots of manual work

    for module configuration (KT-23930) • Several platform codebases can’t sit in one module (different SourceSets )
 • Every platform has its own problems • Kotlin/JS CAVEATS
  27. • Drawbacks of the concept • Lots of manual work

    for module configuration (KT-23930) • Several platform codebases can’t sit in one module (different SourceSets )
 • Every platform has its own problems • Kotlin/JS • One output JS-file per module CAVEATS
  28. • Drawbacks of the concept • Lots of manual work

    for module configuration (KT-23930) • Several platform codebases can’t sit in one module (different SourceSets )
 • Every platform has its own problems • Kotlin/JS • One output JS-file per module • Manual setup for including libs in the output CAVEATS
  29. • Drawbacks of the concept • Lots of manual work

    for module configuration (KT-23930) • Several platform codebases can’t sit in one module (different SourceSets )
 • Every platform has its own problems • Kotlin/JS • One output JS-file per module • Manual setup for including libs in the output • Kotlin/Native CAVEATS
  30. • Drawbacks of the concept • Lots of manual work

    for module configuration (KT-23930) • Several platform codebases can’t sit in one module (different SourceSets )
 • Every platform has its own problems • Kotlin/JS • One output JS-file per module • Manual setup for including libs in the output • Kotlin/Native • Still experimental - some features are not supported CAVEATS
  31. • Drawbacks of the concept • Lots of manual work

    for module configuration (KT-23930) • Several platform codebases can’t sit in one module (different SourceSets )
 • Every platform has its own problems • Kotlin/JS • One output JS-file per module • Manual setup for including libs in the output • Kotlin/Native • Still experimental - some features are not supported • No reuse for multiplatform (yet) CAVEATS
  32. • Re-thinking Multimodule projects configuration • Catching up Kotlin/Native with

    other platforms • Increasing common libs count • kotlin.test • kotlinx.html • kotlinx.serialization • kotlinx.coroutines • kotlinx.io • SQLDelight • … FUTURE PLANS
  33. • Create common business logic, not UI • Write every

    part of the app in one language (optional) WRITE ONCE,.SHARE EVERYWHERE
  34. • Code from the talk https://goo.gl/VYgHmr • Serialization support for

    Kotlin/Native https://github.com/Kotlin/kotlinx.serialization/issues/86 • Channels support for Kotlin/Native https://github.com/Kotlin/kotlinx.coroutines/issues/462 • New Multiplatform configuration approach https://youtrack.jetbrains.com/issue/KT-23930 LINKS