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

The Triumphs and Tribulations of Kotlin/Native ...

The Triumphs and Tribulations of Kotlin/Native In Practice - AppDevCon, Amsterdam, Netherlands - March 2019

First talk about a project I've been working on with K/N!

Abstract:
The promise of write-once-run-everywhere has haunted native mobile developers since the first time someone whispered the words “phone gap”. But what if there was a way to have cross-platform development with a modern, type-safe language? JetBrains is trying to make this happen with Kotlin/Native, which compiles to LLVM bytecode, and can run on iOS, Android, and even the web. Learn more about some of the benefits of working with Kotlin/Native, some of the drawbacks, and a few of the (current) potential dealbreakers when it comes to using this exciting new technology in a real app.

Links:
- Main Project: https://github.com/bakkenbaeck/PorchPirateProtector
- Initial K/N Test: https://github.com/designatednerd/KotlinNativeTest

Ellen Shapiro

March 15, 2019
Tweet

More Decks by Ellen Shapiro

Other Decks in Technology

Transcript

  1. THE TRIUMPHS AND TRIBULATIONS OF KOTLIN/NATIVE IN PRACTICE APPDEVCON |

    AMSTERDAM, NL | MARCH 2019 @DESIGNATEDNERD | BAKKENBAECK.NO | JUSTHUM.COM
  2. THE TRIUMPHS AND TRIBULATIONS OF KOTLIN/NATIVE IN PRACTICE APPDEVCON |

    AMSTERDAM, NL | MARCH 2019 @DESIGNATEDNERD | BAKKENBAECK.NO | JUSTHUM.COM
  3. !

  4. !

  5. !

  6. ! "

  7. // For Native ONLY projects apply plugin: 'kotlin-native-platform' // For

    projects targeting multiple platforms, // for example JVM + Native + JS apply plugin: 'kotlin-multiplatform'
  8. KOTLIN fun printForDay(day: DayOfWeek) { when (day) { DayOfWeek.Monday ->

    println("You can fall apart") DayOfWeek.Tuesday, DayOfWeek.Wednesday -> println("Break my heart") DayOfWeek.Thursday -> println("Doesn't even start") DayOfWeek.Friday -> println("I'm in love") DayOfWeek.Saturday -> println("Wait") DayOfWeek.Sunday -> print("Always comes too late") } }
  9. SWIFT func printForDay(_ day: DayOfWeek) { switch day { case

    .monday: print("You can fall apart") case .tuesday, .wednesday: print("Break my heart") case .thursday: print("Doesn't even start") case .friday: print("I'm in love") case .saturday: print("Wait") case .sunday: print("Always comes too late") default: fatalError("Not a day") }
  10. SWIFT func printForDay(_ day: DayOfWeek) { switch day { case

    .monday: print("You can fall apart") case .tuesday, .wednesday: print("Break my heart") case .thursday: print("Doesn't even start") case .friday: print("I'm in love") case .saturday: print("Wait") case .sunday: print("Always comes too late") default: fatalError("Not a day") }
  11. SWIFT func printForDay(_ day: DayOfWeek) { switch day { case

    .monday: print("You can fall apart") case .tuesday, .wednesday: print("Break my heart") case .thursday: print("Doesn't even start") case .friday: print("I'm in love") case .saturday: print("Wait") case .sunday: print("Always comes too late") default: // <- ! ! ! fatalError("Not a day") }
  12. IOS

  13. IOS

  14. SWIFT @objc class Keychain: NSObject, SecureStorage { static let shared

    = Keychain() private override init() { super.init() } //TODO: Actually use keychain private var token: String? func storeTokenString(token: String) { self.token = token } func clearTokenString() { self.token = nil } func fetchTokenString() -> String? { return self.token } }
  15. SWIFT @objc class Keychain: NSObject, SecureStorage { static let shared

    = Keychain() private override init() { super.init() } //TODO: Actually use keychain private var token: String? func storeTokenString(token: String) { self.token = token } func clearTokenString() { self.token = nil } func fetchTokenString() -> String? { return self.token } }
  16. SWIFT @objc class Keychain: NSObject, SecureStorage { static let shared

    = Keychain() private override init() { super.init() } //TODO: Actually use keychain private var token: String? func storeTokenString(token: String) { self.token = token } func clearTokenString() { self.token = nil } func fetchTokenString() -> String? { return self.token } }
  17. SWIFT @objc class Keychain: NSObject, SecureStorage { static let shared

    = Keychain() private override init() { super.init() } //TODO: Actually use keychain private var token: String? func storeTokenString(token: String) { self.token = token } func clearTokenString() { self.token = nil } func fetchTokenString() -> String? { return self.token } }
  18. KOTLIN object TokenManager { fun currentToken(storage: SecureStorage): UserToken? { storage.fetchTokenString()?.let

    { return UserToken(it) } ?: return null } fun storeToken(token: UserToken, storage: SecureStorage) { storage.storeTokenString(token.token) } fun clearToken(storage: SecureStorage) { storage.clearTokenString() } }
  19. KOTLIN object TokenManager { fun currentToken(storage: SecureStorage): UserToken? { storage.fetchTokenString()?.let

    { return UserToken(it) } ?: return null } fun storeToken(token: UserToken, storage: SecureStorage) { storage.storeTokenString(token.token) } fun clearToken(storage: SecureStorage) { storage.clearTokenString() } }
  20. KOTLIN object TokenManager { fun currentToken(storage: SecureStorage): UserToken? { storage.fetchTokenString()?.let

    { return UserToken(it) } ?: return null } fun storeToken(token: UserToken, storage: SecureStorage) { storage.storeTokenString(token.token) } fun clearToken(storage: SecureStorage) { storage.clearTokenString() } }
  21. SWIFT @objc class Keychain: NSObject, SecureStorage { static let shared

    = Keychain() private override init() { super.init() } //TODO: Actually use keychain private var token: String? func storeTokenString(token: String) { self.token = token } func clearTokenString() { self.token = nil } func fetchTokenString() -> String? { return self.token } }
  22. KOTLIN val creds = UserCredentials("[email protected]", "guessme") val string = Json.stringify(UserCredentials.serializer(),

    creds) // String is '{"username":"[email protected]","password":"guessme"}' val updatedCreds = Json.parse(UserCredentials.serializer(), string) // updatedCreds.username is "[email protected]" // updatedCreds.password is "guessme"
  23. KOTLIN val creds = UserCredentials("[email protected]", "guessme") val string = Json.stringify(UserCredentials.serializer(),

    creds) // String is '{"username":"[email protected]","password":"guessme"}' val updatedCreds = Json.parse(UserCredentials.serializer(), string) // updatedCreds.username is "[email protected]" // updatedCreds.password is "guessme"
  24. KOTLIN val creds = UserCredentials("[email protected]", "guessme") val string = Json.stringify(UserCredentials.serializer(),

    creds) // String is '{"username":"[email protected]","password":"guessme"}' val updatedCreds = Json.parse(UserCredentials.serializer(), string) // updatedCreds.username is "[email protected]" // updatedCreds.password is "guessme"
  25. KOTLIN val creds = UserCredentials("[email protected]", "guessme") val string = Json.stringify(UserCredentials.serializer(),

    creds) // String is '{"username":"[email protected]","password":"guessme"}' val updatedCreds = Json.parse(UserCredentials.serializer(), string) // updatedCreds.username is "[email protected]" // updatedCreds.password is "guessme"
  26. KOTLIN val creds = UserCredentials("[email protected]", "guessme") val string = Json.stringify(UserCredentials.serializer(),

    creds) // String is '{"username":"[email protected]","password":"guessme"}' val updatedCreds = Json.parse(UserCredentials.serializer(), string) // updatedCreds.username is "[email protected]" // updatedCreds.password is "guessme"
  27. IOS

  28. IOS

  29. THINGS YOU'LL LEARN DOING SERVER DEVELOPMENT > Docker > MySQL

    > ORMs for MySQL > One-way hashing for secure password storage
  30. THINGS YOU'LL LEARN DOING SERVER DEVELOPMENT > Docker > MySQL

    > ORMs for MySQL > One-way hashing for secure password storage > Your computer's exact melting point
  31. !"# NEXT STEPS > Build the prototype box > Get

    the Raspberry pi software working
  32. !"# NEXT STEPS > Build the prototype box > Get

    the Raspberry pi software working > Get the raspberry pi actually unlocking the box
  33. !"# NEXT STEPS > Build the prototype box > Get

    the Raspberry pi software working > Get the raspberry pi actually unlocking the box > Work on sharing design elements
  34. !"# NEXT STEPS > Build the prototype box > Get

    the Raspberry pi software working > Get the raspberry pi actually unlocking the box > Work on sharing design elements > Work on sharing localized strings
  35. !"# NEXT STEPS > Build the prototype box > Get

    the Raspberry pi software working > Get the raspberry pi actually unlocking the box > Work on sharing design elements > Work on sharing localized strings > Maybe find someone who knows what they're doing to build it for real?
  36. OBLIGATORY SUMMARY SLIDE! > Kotlin/Native has made great strides in

    the last year > Share logic across iOS, android, and server without killing performance or sacrificing type/null safety
  37. OBLIGATORY SUMMARY SLIDE! > Kotlin/Native has made great strides in

    the last year > Share logic across iOS, android, and server without killing performance or sacrificing type/null safety > it's still beta, You will run into a lot of brick walls
  38. OBLIGATORY SUMMARY SLIDE! > Kotlin/Native has made great strides in

    the last year > Share logic across iOS, android, and server without killing performance or sacrificing type/null safety > it's still beta, You will run into a lot of brick walls > Ktor and kotlinX serialization are a huge help, if you can get around what a mess coroutines can be on iOS
  39. OBLIGATORY SUMMARY SLIDE! > Kotlin/Native has made great strides in

    the last year > Share logic across iOS, android, and server without killing performance or sacrificing type/null safety > it's still beta, You will run into a lot of brick walls > Ktor and kotlinX serialization are a huge help, if you can get around what a mess coroutines can be on iOS > This is experimental, but it's stupid amounts of fun
  40. LINKS! > Kotlin MPP for iOS + Android tutorial https://kotlinlang.org/docs/tutorials/

    native/mpp-ios-android.html > KotlinConf App https://github.com/JetBrains/kotlinconf- app > KotlinLang Slack https://slack.kotlinlang.org
  41. LINKS! > My original Kotlin Native sandbox https://github.com/designatednerd/ KotlinNativeTest >

    Package Thief vs. Glitter Bomb Trap https://youtube.com/watch?v=xoxhDk-hwuo