Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥

Google I/O Extended 2023: What's New in Kotlin ...

Google I/O Extended 2023: What's New in Kotlin for Android

Google I/O Extended 2023: What's New in Kotlin for Android.

Jaewoong

July 14, 2023
Tweet

More Decks by Jaewoong

Other Decks in Technology

Transcript

  1. Index 1. State of Kotlin 2. Kotlin 2.0 Compiler 3.

    Kotlin DSL for Gradle 4. Code Generation (KAPT, KSP) 5. Kotlin Multiplatform
  2. State of Kotlin • 15M+ lines of Kotlin code •

    70+ Android apps by Google built with Kotlin • Thousands of Google engineers write Kotlin
  3. 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
  4. 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.
  5. 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
  6. 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
  7. 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
  8. Kotlin 2.0 compiler // build.gradle.kts (module) kotlin { sourceSets.all {

    languageSettings { languageVersion = "2.0" } } }
  9. 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
  10. 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.
  11. Kotlin 2.0 compiler Separately, a syntax tree (PSI) & a

    table with semantic info (BindingContext)
  12. 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 } }
  13. 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
  14. 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
  15. 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
  16. Kotlin Code Generation Kapt Kotlin Annotation Processing Tool Generates Java

    stubs from Kotlin code, allowing annotations processors written for Java to work with Kotlin.
  17. 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.
  18. 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.
  19. 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
  20. Kotlin Code Generation KSP Support ✅ Jetpack Room ✅ Glide

    ✅ Moshi ✅ … and more! goo.gle/ksp-support
  21. Kotlin Multiplatform jetbrains.com/lp/compose-multiplatform • iOS (Alpha) • Android (via Jetpack

    Compose) • Desktop (Windows, MacOS, Linux) • Web (Experimental)
  22. Kotlin Multiplatform Jetpack Libraries • Annotations • Collections • DataStore

    Network • Ktor • Ktrofit • .. Database • SQLDelight • Realm • KStore Dependency Injection • Koin • Kodein • kotlin-inject Kotlin • Serialization • Coroutines • ..