Search code examples
androidandroid-jetpackandroid-jetpack-compose

The compose compiler plugin you are using (version 1.0.1) expects a minimum runtime version of 1.0.1


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

Solution

  • 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.