0

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
clever_trevor
  • 1,530
  • 2
  • 22
  • 42
  • 1
    why do you have `android` part with `buildFeatures` and `composeOptions` in your project gradle file? It should be inside app file – Phil Dukhov Sep 09 '21 at 04:14

3 Answers3

1

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.

clever_trevor
  • 1,530
  • 2
  • 22
  • 42
0

Try adding this to the project level build

buildscript {
    ext {
        compose_version = '1.0.1' //latest is 1.0.2 though (stable)
    }
}
Richard Onslow Roper
  • 5,477
  • 2
  • 11
  • 42
0

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.
}
Jared Burrows
  • 54,294
  • 25
  • 151
  • 185
raj kavadia
  • 926
  • 1
  • 10
  • 30