shipping multiplatform on ios android ben asher alec
play

SHIPPING MULTIPLATFORM ON IOS & ANDROID BEN ASHER ALEC STRONG - PowerPoint PPT Presentation

SHIPPING MULTIPLATFORM ON IOS & ANDROID BEN ASHER ALEC STRONG @benasher44 @strongolopolis Copenhagen Denmark SHIPPING MULTIPLATFORM ON IOS & ANDROID BEN ASHER ALEC STRONG @benasher44 @strongolopolis Copenhagen Denmark Markups


  1. SHIPPING MULTIPLATFORM ON IOS & ANDROID BEN ASHER ALEC STRONG @benasher44 @strongolopolis Copenhagen Denmark

  2. SHIPPING MULTIPLATFORM ON IOS & ANDROID BEN ASHER ALEC STRONG @benasher44 @strongolopolis Copenhagen Denmark

  3. Markups Link to another sheet

  4. History

  5. Live Info

  6. Championed on iOS Championed on Android ~15 across Android and iOS ~30 across Android and iOS Construction Financial Services

  7. Offline Search Sync System Business Logic

  8. Business Logic Models

  9. MPP Business Logic Models

  10. MPP Business Logic Models

  11. MPP

  12. MPP Kotlin/Native

  13. New tools 🌯🌯🌯 New language 🌯🌯🌯 Uneven ecosystem

  14. Adopting cross-platform in your app has a cost

  15. What is the value that makes it worth the effort?

  16. Diverging Sync Systems

  17. Existing Shared Code

  18. What tools will your cross-platform solution need What is the common goal all stakeholders have

  19. What else? No JNI on Android Obj-C 
 Community Interop Not New Jetbrains For Android

  20. Common Questions Kotlin/Native relies on Obj-C? What about Swift? Obj-C header is well-annotated for Swift This is the status quo for Apple’s own frameworks

  21. Common Questions What about performance? Same performance expectations on Android Can drop into C if needed on iOS

  22. Common Questions What about value types?

  23. Common Questions There’s a garbage collector? But there’s no JVM, right? Bacon’s Algorithm for GC

  24. Common Questions What libraries can we use for mpp? JVM Distributions are incomplete Special multiplatform distributions K/N ABI instability (klib)

  25. Common Questions What is “common” code?

  26. Library Outputs Library Source Sets iosMain iOS - .framework commonMain Android - .aar androidMain

  27. Library Outputs Library Source Sets Code actual class Lock iosMain iOS - .framework expect class Lock commonMain Android - .aar actual class Lock androidMain

  28. Library Outputs Library Source Sets actual class Lock iosMain iOS - .framework commonMain expect class Lock Android - .aar androidMain actual class Lock

  29. Library Outputs Library Source Sets iosMain iOS - .framework commonMain Android - .aar androidMain

  30. Library Outputs Library Source Sets iosMain iOS - .framework commonMain Android - .aar androidMain

  31. Library Outputs Library Source Sets iosMain iOS - .framework commonMain Android - .aar androidMain Windows - .dll windowsMain

  32. commonMain Yes Platform Yes Is it platform agnostic? No Will other common No code use it?

  33. commonMain Yes Platform Yes Is it platform agnostic? No Will other common No code use it?

  34. commonMain Yes Is it platform agnostic? Will other common No code use it?

  35. expect class DatabaseFactory { internal fun createSqliteDriver(): SqlDriver }

  36. Platform Is it platform agnostic? No Will other common No code use it?

  37. sourceSets {A commonMain {B}C androidLibMain {D}E iosLibMain {F}G }H

  38. sourceSets {A commonMain {B}C androidLibMain {D dependencies {I api project(‘:protos') }J }E iosLibMain {F}G }H

  39. fun SearchQueries.insert(entity: SyncEntity) entity: SyncEntity

  40. sourceSets {A commonMain {B}C androidLibMain {D}E iosLibMain {F}G }H

  41. sourceSets {A commonMain {B}C androidLibMain {D}E }H

  42. commonMain Yes Is it platform agnostic?

  43. fun search(terms: String): List<Search>?

  44. Library Source Sets iosMain Host 
 commonMain Application androidMain

  45. Host 
 Application Talks to backend API Talks to existing application state

  46. Library Initialization Host 
 commonMain Application Library defines interface App provides implementation

  47. Case Study: Networking Highly platform-specific Backend API Hosts Current user’s credential

  48. MPP Life Hack: Interface Network Make an API request Receive an async response Interface can be re-implemented later

  49. interface Network { /** * Makes an API request */ fun makeRequest( host: APIHost, request: Request, completion: (Request.Response) -> Unit ): NetworkDisposable }

  50. interface Network { /** * Makes an API request */ fun makeRequest( host: APIHost, host: APIHost request: Request, completion: (Request.Response) -> Unit ): NetworkDisposable } Plain enum of names of the hosts– no URL handling required

  51. data class: interface Network { - String path and body, /** * Makes an API request - query params dict */ fun makeRequest( - enum method (GET, POST, etc.) host: APIHost, request: Request, request: Request completion: (Request.Response) -> Unit ): NetworkDisposable }

  52. interface Network { /** * Makes an API request */ fun makeRequest( host: APIHost, request: Request, completion: (Request.Response) -> Unit completion: (Request.Response) -> Unit ): NetworkDisposable } sealed class w/ different response types:

  53. interface Network { /** * Makes an API request */ fun makeRequest( host: APIHost, request: Request, completion: (Request.Response) -> Unit ): NetworkDisposable NetworkDisposable } Interface with a cancel() method

  54. suspend fun Network.makeRequest( host: APIHost, request: Request ): Request.Response

  55. Concurrency in commonMain actual fun <T> T.freeze(): T = freeze() iosMain expect fun <T> T.freeze(): T commonMain actual fun <T> T.freeze(): T = this androidMain

  56. Shipping Internally iosMain Host 
 commonMain Application androidMain

  57. iosMain Host 
 Host 
 commonMain Application Application androidMain

  58. iosMain Host 
 Host 
 commonMain Application Application androidMain

  59. Pros Cons Minimal change for android Two build environments for iOS Seamless local development CI Nightmare Single source of truth Host dependencies

  60. iosMain Host 
 Host 
 commonMain Application Application androidMain

  61. iosMain Host 
 Host 
 commonMain Application Application androidMain

  62. iosMain Host 
 Host 
 commonMain commonMain Application Application androidMain

  63. Host 
 Host 
 Application Application commonMain commonMain androidMain iosMain

  64. Pros Cons Minimal change for android Two build environments for iOS Seamless local development CI Nightmare for iOS Host dependencies Out of sync code

  65. iosMain Host 
 Host 
 commonMain Application Application androidMain

  66. Host 
 Host 
 Application Application iosMain commonMain androidMain

  67. Pros Cons Breaking changes are painful CI is fast Need good CD setup Encourages unit test coverage Debugging decoupled repos Single source of truth

  68. iosMain Host 
 Host 
 commonMain Application Application androidMain

  69. iosMain Host 
 Host 
 Application Application commonMain androidMain

  70. commonMain Host 
 Host 
 Application Application androidMain

  71. Shipping Externally Test Crashing!

  72. Shipping Externally fun crash() { (null as String?)!! }

  73. Shipping Externally setUnhandledExceptionHook()

  74. Shipping Externally What happens if a Worker crashes?

  75. Review Define your project’s goals Be thoughtful growing your codebase Avoid solving general muliplatform problems Get your CI and dev setup working early Join us in Kotlin slack

  76. THANK YOU AND REMEMBER TO VOTE Ben Asher @benasher44 Alec Strong @Strongolopolis #KotlinConf

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend