Slide 1

Slide 1 text

What's New in Kotlin for Android

Slide 2

Slide 2 text

Jaewoong Eum (엄재웅) Lead Android Developer Advocate, Stream Google Developer Expert skydoves @github_skydoves

Slide 3

Slide 3 text

Index 1. State of Kotlin 2. Kotlin 2.0 Compiler 3. Kotlin DSL for Gradle 4. Code Generation (KAPT, KSP) 5. Kotlin Multiplatform

Slide 4

Slide 4 text

State of Kotlin

Slide 5

Slide 5 text

State of Kotlin 2017 goo.gle/5-years-of-kotlin

Slide 6

Slide 6 text

State of Kotlin goo.gle/kotlin-first 2019

Slide 7

Slide 7 text

State of Kotlin ● 15M+ lines of Kotlin code ● 70+ Android apps by Google built with Kotlin ● Thousands of Google engineers write Kotlin

Slide 8

Slide 8 text

State of Kotlin

Slide 9

Slide 9 text

State of Kotlin

Slide 10

Slide 10 text

State of Kotlin

Slide 11

Slide 11 text

State of Kotlin

Slide 12

Slide 12 text

State of Kotlin 95% of top 100 apps use Kotlin 70% of top 1000 apps use Kotlin in their own code 55% of apps that use Kotlin use coroutines in their own code

Slide 13

Slide 13 text

State of Kotlin

Slide 14

Slide 14 text

State of Kotlin github.com/Kotlin/KEEP

Slide 15

Slide 15 text

State of Kotlin kotlinconf.com/talks/374446/

Slide 16

Slide 16 text

The Kotlin 2.0 Compiler

Slide 17

Slide 17 text

Kotlin 2.0 compiler The K2 compiler frontend is not just a refactoring of the old compiler frontend, but a complete rewrite from scratch based on the new architecture.

Slide 18

Slide 18 text

Kotlin 2.0 compiler Kotlin 2.0 compiler performance Project Kotlin 1.8 compiler Kotlin 2.0 compiler Improvement Kotlin 5m 40s 2.0 KLOC/s 2m 37s 6.3 KLOC/s ~2.2x IntelliJ IDEA Ultimate 34m 15s 2.5 KLOC/s 16m 59s 5.0 KLOC/s ~2.0x

Slide 19

Slide 19 text

2022 2023 2024 Kotlin releases 1.7.0 K2 Alpha 1.9.x K2 Beta Compose & KSP 1.8.20 "lang ver 2.0" 2.0 K2 Default K2 integration in Android Studio Kotlin 2.0 compiler

Slide 20

Slide 20 text

Kotlin 2.0 compiler 2022 2023 2024 Kotlin releases 1.7.0 K2 Alpha 1.9.x K2 Beta Compose & KSP 1.8.20 "lang ver 2.0" 2.0 K2 Default K2 integration in Android Studio

Slide 21

Slide 21 text

Kotlin 2.0 compiler // build.gradle.kts (module) kotlin { sourceSets.all { languageSettings { languageVersion = "2.0" } } }

Slide 22

Slide 22 text

Kotlin 2.0 compiler

Slide 23

Slide 23 text

2022 Kotlin 2.0 compiler 2022 2023 2024 Kotlin releases 1.7.0 K2 Alpha 1.9.x K2 Beta Compose & KSP 1.8.20 "lang ver 2.0" 2.0 K2 Default K2 integration in Android Studio

Slide 24

Slide 24 text

Kotlin 2.0 compiler Will it break my code? Kotlin changes with every language version update. New language features get introduced and old bugs get fixed. We always try to minimize the number and impact of breaking changes and follow the Kotlin language evolution process. Kotlin 2.0 will be no different in that respect.

Slide 25

Slide 25 text

Kotlin 2.0 compiler

Slide 26

Slide 26 text

Kotlin 2.0 compiler

Slide 27

Slide 27 text

Kotlin 2.0 compiler Separately, a syntax tree (PSI) & a table with semantic info (BindingContext)

Slide 28

Slide 28 text

Kotlin 2.0 compiler

Slide 29

Slide 29 text

Kotlin 2.0 compiler https://youtu.be/wUGfuWHCqrc https://youtu.be/iTdJJq_LyoY

Slide 30

Slide 30 text

No content

Slide 31

Slide 31 text

Kotlin DSL for Gradle

Slide 32

Slide 32 text

Kotlin DSL for Gradle Builds

Slide 33

Slide 33 text

Kotlin DSL for Gradle Builds

Slide 34

Slide 34 text

Kotlin DSL for Gradle Builds

Slide 35

Slide 35 text

Kotlin DSL for Gradle Builds plugins { id("com.android.application") id("org.jetbrains.kotlin.android") } android { namespace = "com.skydoves.balloon" compileSdk = 33 defaultConfig { applicationId = "com.skydoves.balloon" minSdk = 21 } buildFeatures { compose = true } }

Slide 36

Slide 36 text

Kotlin DSL for Gradle Builds plugins { id("com.android.application") id("org.jetbrains.kotlin.android") } android { namespace = "com.skydoves.balloon" compileSdk = 33 asdf = "asdf" defaultConfig { applicationId = "com.skydoves.balloon" minSdk = 21 } buildFeatures { compose = true } } Unresolved reference: asdf

Slide 37

Slide 37 text

Kotlin DSL for Gradle Builds

Slide 38

Slide 38 text

Kotlin DSL for Gradle Builds

Slide 39

Slide 39 text

Kotlin DSL for Gradle Builds

Slide 40

Slide 40 text

Kotlin DSL for Gradle Builds Kotlin DSL [Default] Write your build scripts in Kotlin, with editor support in the IDE Kotlin DSL with Version Catalogs [Experimental] Manage dependencies and plugins in a maintainable and scalable way goo.gle/migrate-to-kts goo.gle/migrate-to-catalogs

Slide 41

Slide 41 text

A fully functional Android app built entirely with Kotlin and Jetpack Compose. You can find out Kotlin DSL scripts, Version Catalogs, and build logic examples! Now in Android goo.gle/nia

Slide 42

Slide 42 text

Kotlin Code Generation

Slide 43

Slide 43 text

Kotlin Code Generation JSR 269: Pluggable Annotation Processing API

Slide 44

Slide 44 text

Kotlin Code Generation

Slide 45

Slide 45 text

Kotlin Code Generation

Slide 46

Slide 46 text

Kotlin Code Generation

Slide 47

Slide 47 text

Kotlin Code Generation Kapt Kotlin Annotation Processing Tool Generates Java stubs from Kotlin code, allowing annotations processors written for Java to work with Kotlin.

Slide 48

Slide 48 text

Kotlin Code Generation Kapt Kotlin Annotation Processing Tool Generates Java stubs from Kotlin code, allowing annotations processors written for Java to work with Kotlin. Kotlin code Java stubs Java Annotation Processors Kapt uses Java compiler to run annotation processors.

Slide 49

Slide 49 text

Kotlin Code Generation KSP Kotlin Symbol Processing A Kotlin-first alternative to kapt, directly analyzing Kotlin code.

Slide 50

Slide 50 text

Kotlin Code Generation KSP Kotlin Symbol Processing A Kotlin-first alternative to kapt, directly analyzing Kotlin code. Kotlin code KSP Processors KSP uses Kotlin compiler to run annotation processors.

Slide 51

Slide 51 text

Kotlin Code Generation Up to 2x speed No stub generation step required Better typing Understands Kotlin specific language features, such as nullability Multiplatform-ready Doesn't depend on Java source code Advantages of KSP

Slide 52

Slide 52 text

Kotlin Code Generation KSP Migration Strategy

Slide 53

Slide 53 text

Kotlin Code Generation KSP Migration Strategy

Slide 54

Slide 54 text

Kotlin Code Generation KSP Migration Strategy

Slide 55

Slide 55 text

Kotlin Code Generation KSP Support ✅ Jetpack Room ✅ Glide ✅ Moshi ✅ … and more!

Slide 56

Slide 56 text

Kotlin Code Generation KSP Support ✅ Jetpack Room ✅ Glide ✅ Moshi ✅ … and more! goo.gle/ksp-support

Slide 57

Slide 57 text

Kotlin Code Generation

Slide 58

Slide 58 text

Kotlin Code Generation KSP for Dagger & Hilt is coming!

Slide 59

Slide 59 text

Kotlin Multiplatform

Slide 60

Slide 60 text

Kotlin Multiplatform Shared business logic written in Kotlin between platforms

Slide 61

Slide 61 text

Kotlin Multiplatform

Slide 62

Slide 62 text

Kotlin Multiplatform jetbrains.com/lp/compose-multiplatform ● iOS (Alpha) ● Android (via Jetpack Compose) ● Desktop (Windows, MacOS, Linux) ● Web (Experimental)

Slide 63

Slide 63 text

Kotlin Multiplatform github.com/JetBrains/compose-multiplatform

Slide 64

Slide 64 text

Kotlin Multiplatform

Slide 65

Slide 65 text

Kotlin Multiplatform Jetpack Libraries ● Annotations ● Collections ● DataStore

Slide 66

Slide 66 text

Kotlin Multiplatform Jetpack Libraries ● Annotations ● Collections ● DataStore Network ● Ktor ● Ktrofit ● .. Database ● SQLDelight ● Realm ● KStore Dependency Injection ● Koin ● Kodein ● kotlin-inject Kotlin ● Serialization ● Coroutines ● ..

Slide 67

Slide 67 text

Kotlin Multiplatform kotlinlang.org/lp/multiplatform/case-studies

Slide 68

Slide 68 text

Thank you! Lead Android Developer Advocate @ GetStream Jaewoong Eum (엄재웅) Google Developer Expert