I will show you how you can add Compose Compiler to your Android Studio project.
Add Compose Compiler To Android Studio
Information
The Compose Compiler is a plugin that works with the Kotlin Compiler to process @Composable elements in Android development.
Jetpack Compose has been, in my opinion, an absolute blessing for Android. It offers the ability to quickly and efficiently create custom elements for the UI along with animations due to recomposition.
Recomposition gives the app the ability to change the UI based on state changes. The UI change could be a single element or a container element. The change could be invoking a new value to be displayed or parameter value used for animations.
Configuration
You will need to edit a few files to add Compose Compiler.
Build.gradle
First is the top level Project build.gradle file. You will need to add a single line.
alias(libs.plugins.compose.compiler) apply falseSo your gradle for your new project will look similar to this.
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
alias(libs.plugins.android.application) apply false
alias(libs.plugins.jetbrains.kotlin.android) apply false
alias(libs.plugins.compose.compiler) apply false
}Next you will need to add single line to your module/app build.gradle file.
alias(libs.plugins.compose.compiler)So your gradle will now look similar to this for newly created projects.
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.jetbrains.kotlin.android)
alias(libs.plugins.compose.compiler)
}
android {
...
}
dependencies {
...
}Libs.versions.toml
Now you will need to add the library into your libs.versions.toml file.
You will need to scroll to bottom and add the following line in the plugins section.
compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }The bottom section for a newly created project should look similar to this.
[plugins]
android-application = { id = "com.android.application", version.ref = "agp" }
jetbrains-kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }This is where I had a few issues. Personally the issue came from the different version numbers weren't compatible with one another. After some research, I found a "cocktail" of compatible versions. Below is what I ended up with. There may be a better alternative or I may have missed something but this is what I did to be able to get it to work as of writing this article.
Edit this on the top of the libs.versions.toml file
[versions]
agp = "8.4.2"
kotlin = "2.0.0"
coreKtx = "1.13.1"I hope this was helpful. Leave a comment if there is something I missed.
