Adding Compose Compiler To Android Studio Project

I will show you how you can add Compose Compiler to your Android Studio project.

You will need to edit a few files.

First is the top level Project gradle file. You will need to add a single line

    alias(libs.plugins.compose.compiler) apply false

So 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 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 {

...

}

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

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 have have missed something but this is what I was able to get 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.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *