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

Fast Prototypes with Flutter + Kotlin/Native

JB Lorenzo
November 16, 2018

Fast Prototypes with Flutter + Kotlin/Native

Tasked with making the app for our upcoming internal OLX Group conference and having a lot already on our plate, my team was thinking of how to reduce the time for us to make an app for both iOS and Android. The first thing that came to my mind was using Kotlin, as it has a way to compile on other platforms. Not everything went as planned, but (spoiler alert) we made it in time, and we learned a lot!

JB Lorenzo

November 16, 2018
Tweet

More Decks by JB Lorenzo

Other Decks in Programming

Transcript

  1. we fuel local economies by making it super easy for

    anyone to buy or sell almost anything through our platforms Our Mission
  2. Who We Are we operate a network of market-leading trading

    platforms in over 40 countries that are used by more than 350 million people every month to buy and sell almost anything
  3. Our Numbers brands 17 + people 500 0+ daily listings

    1M + offices 35 daily events 4B + daily notifications 50M + monthly users 350M + countries 43 shopping app (20+ markets) #1
  4. Outline: - Why? - How? (to Setup) - How? (to

    use it) - What? (pitfalls, considerations)
  5. What project structure works? - Kotlin/Native_version = ‘0.8.2’ - kotlin_version

    = ‘1.2.31' - flutter: sdk: flutter - google_sign_in: 3.0.5 - url_launcher: ^3.0.3 - device_calendar: 0.0.6
  6. // settings.gradle include ':app' def flutterProjectRoot =rootProject.projectDir.parentFile.toPath() def plugins =new

    Properties() def pluginsFile =new File(flutterProjectRoot.toFile(), '.flutter-plugins') if (pluginsFile.exists()) { pluginsFile.withReader('UTF-8') { reader -> plugins.load(reader) } } plugins.each { name, path -> def pluginDirectory=flutterProjectRoot.resolve(path).resolve('android').toFile() include":$name" project(":$name").projectDir =pluginDirectory }
  7. // settings.gradle include ':app' // ... some flutter directives include

    ':common' includė ':ios' project(":ios").projectDir = new File("ios") project(":common").projectDir = new File("common")
  8. // ios/build.gradle buildscript { // ... kotlin-native classpath and repositories

    } apply plugin: 'konan' konan.targets = ['iphone', 'iphone_sim'] konanArtifacts { framework('YourFrameworkName') { enableMultiplatform true } } dependencies { expectedBy project(':common') }
  9. // common/build.gradle // ... kotlin-gradle classpath apply plugin: 'kotlin-platform-common' group

    = 'com.olxgroup.olxconf' // ... repositories dependencies { compile "org.jetbrains.kotlin:kotlin-stdlib-common: $kotlin_version" }
  10. iOS // AppDelegate.swift import YourFrameworkName // from Kotlin-Native // ...

    let channel = FlutterMethodChannel.init(name: "/channel", binaryMessenger: controller) channel.setMethodCallHandler({(call: FlutterMethodCall, result: @escaping FlutterResult) -> Void in // Process call.method and result }); GeneratedPluginRegistrant.register(with: self)
  11. Pitfalls * Packing and Unpacking (Object passing into FlutterChannel) *

    Kotlin Companion objects in Swift * Kotlin-Native version dependent support (e.g. for arm32) * Kotlin-Native without JVM is not typical (missing standard libraries, e.g. url parsing)
  12. Takeaways * Flutter is awesome for fast prototypes * Flutter

    and Kotlin/Native are still in beta but is usable already though with some limitations * Kotlin/Native works well to reduce the amount of platform specific code * Some glue code needs to be written to pass around/ serialize objects * Don’t be afraid to try out new technologies (but …)