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

Yet Another KMP*

Ilker Aslan
November 15, 2022

Yet Another KMP*

Ilker Aslan

November 15, 2022
Tweet

More Decks by Ilker Aslan

Other Decks in Programming

Transcript

  1. Targets android() jvm() watchosArm64 { binaries { /* Export an

    unoptimized version */ this.DEBUG = true } } iosArm64 { binaries { /* Export an optimized version */ this.DEBUG = false } }
  2. Predefined Source Sets kotlin { sourceSets { val commonMain by

    getting val commonTest by getting /* if we target jvm platform */ val jvmMain by getting val jvmTest by getting } }
  3. Custom Source Sets kotlin { sourceSets { val commonMain by

    sourceSets.getting val iosX64Main by sourceSets.getting val iosArm64Main by sourceSets.getting val iosMain by sourceSets.creating { dependsOn(commonMain) iosX64Main.dependsOn(this) iosArm64Main.dependsOn(this) } } }
  4. kotlin { iosArm64 { /* Apple iOS on ARM64 platforms*/

    } iosX64 { /* Apple iOS simulator on x86_64 platforms */ compilations { val old by compilations.creating { defaultSourceSet { languageSettings { languageVersion = "1.5" } } } tasks.register<Exec>("old") { println("Compiling for an old version") } } }
  5. expect fun debugLog(message: String) // Android implementation actual fun debugLog(message:

    String) { Timber.d(message) } // JS implementation actual fun debugLog(message: String) { console.log(message) }
  6. class SharedNetworkClient( private val api: String ) { private val

    client = HttpClient() { defaultRequest { url("api") } } suspend fun getUser(): String { val response = client.get() return response.bodyAsText() } }