Background
In the year end of 2022, Kotlin 1.8 was launched. We can now use Kotlin 1.8 as stable version. Let's set up Android project with Kotlin 1.8 .
For the current basic development, We use JetpackCompose which is super powerful framework for Android UI development. Therefore we need to care compose compiler.
google/ksp is one of the lightweight compiler plugin which is developed by google. Some jetpack libraries are supporting that configures with ksp (ex: room).
Set up
Here is a complete example that uses Kotlin 1.8 (+ ksp and compose). PTAL, if you don't have time.
project level gradle file
Use 1.8.0 as Kotlin version.
plugins {
id 'org.jetbrains.kotlin.android' version '1.8.0' apply false
}
module level gradle file
For ksp
Set "1.8.0-1.0.8"
version for ksp.
plugins {
kotlin("android")
id("com.google.devtools.ksp").version("1.8.0-1.0.8")
}
For compose compiler
Also, compose compiler version is strongly depends on Kotlin version. So that we have to update kotlinCompilerExtensionVersion
in composeOptions
block.
I refer to android developer site but there are no compatible version with Kotlin 1.8 . So that we need to refer as other way.
Here is latest compose compiler maven indexes.
And this site provides cutting edge version binaries. It's ok to download .jar
and include to project but it's not recommended. We can set set gradle file like as below.
Step 1. Set new maven repository in settings.gradle
maven {
url "https://androidx.dev/storage/compose-compiler/repository/"
}
Step 2. Refer compatible version commit that indicates in this site.
For now, we would like to use Kotlin 1.8, so that use 1.4.0-dev-k1.8.0-33c0ad36f83
as kotlinCompilerExtensionVersion
android {
composeOptions {
kotlinCompilerExtensionVersion = "1.4.0-dev-k1.8.0-33c0ad36f83"
}
}
And I created complete example project. Please refer the detail configuration settings. => https://github.com/chigichan24/LauncherTest
Conclusion
I post how configure the project with Kotlin 1.8. Compose compiler does not support Kotlin 1.8 yet as stable. So we have to refer not tag but the commit. In the future compose compiler version that 1.4.0
or 1.4.1
(?) will support Kotlin 1.8 definitely. So this post is temporary fix. After launched stable version of compose compiler, don't forget to update it.
Have a great Android application development :)
Reference
- https://developer.android.com/jetpack/androidx/releases/compose-kotlin
- https://androidx.dev/storage/compose-compiler/repository
- https://github.com/chigichan24/LauncherTest
- https://github.com/jimgoog/ComposeAppUsingPrereleaseComposeCompiler
"The Android robot is reproduced or modified from work created and shared by Google and used according to terms described in the Creative Commons 3.0 Attribution License."
Top comments (0)