Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why am I getting 'Compose Compiler Gradle plugin is required' in Kotlin 1.9 project?

I’m working on an Android project using Kotlin version 1.9.0, and I'm encountering the following error message when trying to build my project:

Starting in Kotlin 2.0, the Compose Compiler Gradle plugin is required when compose is enabled. See the following link for more information: https://d.android.com/r/studio-ui/compose-compiler

Here is a snippet of my build.gradle file:

allprojects {
buildscript {
    ext.kotlin_version = '1.9.0'
    repositories {
        google()
        mavenLocal()
        mavenCentral()
        maven { url 'https://jitpack.io' }
        maven { url 'https://developer.huawei.com/repo/' }
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:8.5.2'
        classpath "io.realm:realm-gradle-plugin:10.18.0"
        classpath 'com.google.gms:google-services:4.4.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.20"
        classpath 'com.google.firebase:firebase-crashlytics-gradle:3.0.2'
        classpath 'com.huawei.agconnect:agcp:1.9.1.303'
        classpath 'com.huawei.hms.plugin:analytics:5.0.1.300'
        classpath 'androidx.navigation:navigation-safe-args-gradle-plugin:2.8.0'
    }
}
}

android {
   compileOptions {
    coreLibraryDesugaringEnabled true
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

kotlinOptions {
    jvmTarget = JavaVersion.VERSION_1_8.toString()
}

buildFeatures {
    dataBinding = true
    compose = true
}

composeOptions {
    kotlinCompilerExtensionVersion "1.5.14"
}
}

Even though my project is using Kotlin 1.9.0, I still receive the message about the Compose Compiler plugin required for Kotlin 2.0. I have set kotlinCompilerExtensionVersion to "1.5.14" in composeOptions. Why am I getting this error?

like image 442
alexC Avatar asked Nov 28 '25 08:11

alexC


2 Answers

This issue is occurring because you are using kotlin version > 2.0.0, and in Kotlin 2.0+, the compose compiler is no longer bundled with kotlin itself. It must be explicitly declared as a plugin.

[versions]
kotlin = "2.1.0"
[plugins]
jetbrains-kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }

so according to official documentation (link) if you are using kotlin version > 2.0.0, you need to add this compose-compiler

in libs.versions.toml

[plugins]
compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }

Add the Compose Compiler plugin in both the project-level and app-level build.gradle.kts files

plugins {
   // Existing plugins
   alias(libs.plugins.compose.compiler) apply false
}
plugins {
   // Existing plugins
   alias(libs.plugins.compose.compiler)
}
like image 179
Vishal Anand Avatar answered Nov 30 '25 21:11

Vishal Anand


For older projects not using Kotlin (*.kts) build scripts and libs.versions.toml but using Kotlin version >= 2.0

First add the classpath in the dependencies section of your root build.gradle file:

dependencies {
    //.. other classpaths
    classpath "org.jetbrains.kotlin.plugin.compose:org.jetbrains.kotlin.plugin.compose.gradle.plugin:$kotlin_version"
}

And then in the build.gradle file for each module using compose, apply the compose compiler plugin like so:

apply plugin: "org.jetbrains.kotlin.plugin.compose"
like image 44
devanshu_kaushik Avatar answered Nov 30 '25 21:11

devanshu_kaushik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!