What’s new in Kotlin for Android, #GoogleIO 2023
Last year in 2022, Kotlin completed 5 whole years as the officially supported language for Android Development. Here’s a list of 4 new updates to the Android Kotlin Ecosystem that were announced in Google IO ’23.
Kotlin compiler version 2.0
If you’re a Kotlin developer, you might be excited to hear that the language is getting a major upgrade with version 2.0. What’s cool is that the new Kotlin compiler version 2.0 will be the default one for Kotlin 2.0.
This heavily enhances the performance as compared to previous Kotlin Compiler version 1.8.
Final updates are to be given by the next year(2024). With Kotlin 2.0 compiler Google is aiming for higher developer productivity, ease of use, and the new 2.0 compiler will also encourage more feature advancements in the Kotlin Language.
If you want to try out the new Kotlin 2.0 compiler simply update the Kotlin language version to 2.0 in your module’s Gradle Build file.
Kotlin DSL for Gradle Builds
Google is absolutely bullish on promoting the use of Kotlin Language to completely develop Android Apps. Starting from Android Studio Giraffe the default DSL script for writing Gradle Build Script files will be Kotlin DSL instead of Groovy DSL.
To use the Kotlin DSL in your Gradle build script, simply name your file
build.gradle.kts instead of
One advantage of using Kotlin DSL is that it makes syntax hinting much accurate, and syntax errors are reported right there even before syncing the build.gradle files.
Apart from this developers can also use Gradle version catalogs to put all the Apps dependencies at one centralised place, which sounds amazing for the purpose of scalability.
Check this up : If you’re looking to migrate Gradle build logic from Groovy to Kotlin.
To see a sample, checkout NowInAndroid repository on Github.
KSP(Kotlin Symbol Processor) : a better alternative to Kapt(Kotlin Annotation Processing Tool)
Originally Kapt was used to generate Java Stubs from Kotlin code, allowing annotation processors written in Java to work with Kotlin.
Through Kapt, annotation processing was a time consuming two step procedure.
KSP is a Kotlin-first alternative to Kapt, for directly analysing Kotlin code.
KSP has following advantages over Kapt,
- It’s 2X faster, as it doesn’t have to generate Java stubs.
- Better typing : as it understands Kotlin language specific nuances like nullability.
- It’s multiplatform ready as it doesn’t depend on Java source code.
To get started with migrating from Kapt to KSP checkout the following official migration documentation.
Popular libraries like -> Room, Glide, Moshi…to name a few, have already added support for KSP. Whereas, Dagger and Hilt are yet to support KSP.
Kotlin Multiplatform is still beta, and in experimental stages. Google is bringing three popular Jetpack libraries to the Kotlin Multiplatform ecosystem, they are -> Annotations, Collections, and DataStore
I personally believe that multiplatform is the future of Mobile Development. And any step in that direction seems like the right step.
To see the use of DataStore in Kotlin Multiplatform check this kmm-samples repo. And to read more about Kotlin Multiplatform read this official documentation.
If you found this insightful, do give it an upvote. Thanks.