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

Kotlin Multiplataforma

Avatar for Leandro Leandro
August 31, 2019

Kotlin Multiplataforma

Avatar for Leandro

Leandro

August 31, 2019

Other Decks in Technology

Transcript

  1. Plataforma Android Business Network Storage Analytics Business Interface Implementação Interface

    Interface Interface Network Storage Analytics Implementação Implementação Implementação
  2. Plataforma Android Business Network Storage Analytics Business Interface Implementação Interface

    Interface Interface Network Storage Analytics Implementação Implementação Implementação Kotlin-common
  3. Como funciona Kotlin Multiplataforma kotlin-js kotlin-common kotlin-jvm Kotlin-common expect fun

    logDebug(message: String) JVM actual fun logDebug(message: String) { println("Debug: $message") } JS actual fun logDebug(message: String) { console.log(message) }
  4. Plataforma Android Business Network Storage Analytics Business Interface Implementação Interface

    Interface Interface Network Storage Analytics Implementação Implementação Implementação Kotlin-common
  5. Ktor Android engine iOS engine Ktor library Kotlin-common Pode usar

    a engine do OkHttp ou a do Android sem nenhuma dependência Usa uma NSURLSession assíncrona val client = HttpClient(Apache) { install(JsonFeature) { serializer = GsonSerializer { // .GsonBuilder serializeNulls() disableHtmlEscaping() } } } val message = client.post<HelloWorld> { url(URL("http://127.0.0.1:8080/")) contentType(ContentType.Application.Json) body = HelloWorld(hello = "world") }
  6. Eliminando a dependência do Android SQLDelight Database Você escreve as

    queries em SQLite Driver Android Driver iOS Biblioteca SQLDelight É gerado o banco de dados pronto para ser usado no kotlin-common Database Aplica o plugin
  7. Eliminando a dependência do Android Analytics Analytics Interface Implementação Kotlin-common

    Android API (actual) iOS API (actual) API wrapper (expect) Interface
  8. Projeto Multiplataforma (MPP) View View Model Business Network Storage Analytics

    ViewController Android Analytics API iOS Analytics API Storyboard
  9. Kotlin Multiplataforma Kotlin (Android, JVM, JS) Estável Version 1.3.50 Kotlin/Native

    Beta Plugin version 1.3.50 Coroutines Estável Version 1.3.0 Ktor Estável Version 1.2.3 kotlinx.Serialization Version 0.12.0 Sqldelight Estável Version 1.2.0
  10. Kotlin Lang Multiplatform Project: iOS and Android -Exporta JAR para

    Android - Exporta framework para iOS apply plugin: 'kotlin-multiplatform' kotlin { targets { jvm('android') iOSTarget('iOS') { binaries { framework {baseName='SharedCode'} } } } … task packForXCode(type: Sync) { ... }
  11. IntelliJ IDEA Ultimate Executa a compilação do código common na

    hora apply plugin: 'kotlin-multiplatform' kotlin { android("android") iosX64("iOS") { binaries { framework() } } … task copyFramework { … }
  12. IntelliJ AppCode Tem exemplos usando framework plugins { kotlin("multiplatform") kotlin("xcode-compat")

    version "0.2.3" } kotlin { xcode { setupFramework("KotlinNativeFramework") } }
  13. Blog do Kotlin CocoaPods sample (atualizado com Kotlin 1.3.50) Kotlin

    1.3.30 release notes plugins { kotlin("multiplatform") id("org.jetbrains.kotlin.native.cocoapods") } kotlin { android("android") iosX64("iOS") //iosArm64("iOS") cocoapods { summary = "KotlinNativeFramework" pod("AFNetworking", "~> 3.2.0") } }
  14. Configuração das dependências plugins { kotlin("multiplatform") } kotlin { ...

    sourceSets { commonMain { dependencies { … } } commonTest { dependencies { … } } androidMain { dependencies { … } } iOSMain { dependencies { … } } }
  15. Alguns problemas :( • Problemas com IDE: Auto-import e buscar

    referências; • Quem vai escrever o código para multiplataforma; • Invalidate caches & restart; • Problemas no código em Swift; • Biblioteca de data;