Reputation: 1694
I am integrating Jetpack Compose into my app's legacy
module and running into an issue IncompatibleComposeRuntimeVersionException
when building. I'd like help resolving it.
androidx.compose.compiler.plugins.kotlin.IncompatibleComposeRuntimeVersionException: You are using an outdated version of Compose Runtime that is not compatible with the version of the Compose Compiler plugin you have installed. The compose compiler plugin you are using (version 1.0.1) expects a minimum runtime version of 1.0.1.
at androidx.compose.compiler.plugins.kotlin.VersionChecker.outdatedRuntimeWithUnknownVersionNumber(VersionChecker.kt:116)
at androidx.compose.compiler.plugins.kotlin.VersionChecker.check(VersionChecker.kt:81)
at androidx.compose.compiler.plugins.kotlin.ComposeIrGenerationExtension.generate(ComposeIrGenerationExtension.kt:57)
...
I've been following the official guide, and checked the other relevant stackoverflow post for answers. My app's code closely matches the official guide, and the relevant SO post did not help.
Here are the dependencies
compose_activity: "androidx.activity:activity-compose:1.3.1",
compose: [ // versions.androidx.compose = 1.0.1
"androidx.compose.ui:ui:${versions.androidx.compose}",
"androidx.compose.ui:ui-tooling:${versions.androidx.compose}",
"androidx.compose.material:material:${versions.androidx.compose}",
"androidx.compose.foundation:foundation:${versions.androidx.compose}",
"androidx.compose.runtime:runtime:${versions.androidx.compose}",
"androidx.compose.runtime:runtime-livedata:${versions.androidx.compose}",
"androidx.compose.runtime:runtime-rxjava2:${versions.androidx.compose}",
],
In the project build.gradle
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
dependencies {
classpath "com.android.tools.build:gradle:7.0.1"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.21"
}
android {
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion '1.0.1'
}
kotlinOptions {
jvmTarget = '1.8'
}
}
In the app, legacy, and project build.gradle
buildFeatures {
// Enables Jetpack Compose for this module
compose true
}
In the common-ui module (implemented in app and legacy modules)
api libs.androidx.compose
api libs.androidx.compose_activity
Upvotes: 0
Views: 4180
Reputation: 149
In my case, I had two build flavors - free and paid. I was using compose in only paid flavor variant of my app like so -
paidImplementation("groupId:artifactId:version")
for all the compose-related dependencies...
In my app module, I was even using the compose compiler plugin, since in newer versions, we no need to specify composeCompilerExtensionVersion in composeOptions.
app gradle:
plugins {
alias libs.plugins.com.android.application
alias libs.plugins.org.jetbrains.kotlin.android
alias libs.plugins.org.jetbrains.kotlin.plugin.compose
alias libs.plugins.org.jetbrains.kotlin.kapt
}
project gradle:
buildscript {
dependencies {
classpath(libs.android.tools.build.gradle)
classpath(libs.kotlin.gradle.plugin)
}
}
plugins {
alias libs.plugins.com.android.application apply false
alias libs.plugins.org.jetbrains.kotlin.android apply false
alias libs.plugins.org.jetbrains.kotlin.plugin.compose apply false
alias libs.plugins.org.jetbrains.kotlin.kapt apply false
}
So, I had to use "implementation" for activity compose dependency instead of "paidImplementation" since the compiler was complaining about the expectation of a minimum runtime version of 1.0.0 for the compose compiler plugin version (1.5.14) that I was using.
To fix this, do:
implementation(libs.androidx.activity.compose)
instead of:
paidImplementation(libs.androidx.activity.compose) //or flavorImplementation(libs.androidx.activity.compose)
My dependency versions in libs.versions.toml (version catalogs):
[versions]
agp = "8.8.0"
kotlin = "2.1.0"
activityCompose = "1.10.0"
composeBom = "2025.01.00"
[libraries]
androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "activityCompose" }
androidx-compose-bom = { module = "androidx.compose:compose-bom", version.ref = "composeBom"}
# other dependencies
[plugins]
com-android-application = { id = "com.android.application", version.ref = "agp" }
org-jetbrains-kotlin-plugin-compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
org-jetbrains-kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
org-jetbrains-kotlin-kapt = { id = "org.jetbrains.kotlin.kapt", version.ref = "kotlin" }
Upvotes: 0
Reputation: 1073
For now, you can change the kotlin version to 1.5.21 for compatibility with the jetpack compose in the build gradle project-level file.
plugins {
id 'com.android.application' version '7.1.0-beta05' apply false
id 'com.android.library' version '7.1.0-beta05' apply false
id 'org.jetbrains.kotlin.android' version '1.5.21' apply false // here change the version.
}
Upvotes: 0
Reputation: 1694
The solution was to move the Compose setup code in composeOptions
, buildFeatures
, compileOptions
to the legacy
module, where the Compose code was being written. The official docs specify the app
module, which will not always be accurate.
Upvotes: 1
Reputation: 6863
Try adding this to the project level build
buildscript {
ext {
compose_version = '1.0.1' //latest is 1.0.2 though (stable)
}
}
Upvotes: 0