您正在使用的 compose 编译器插件(版本 1.0.1)要求最低运行时版本为 1.0.1

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

我正在将 Jetpack Compose 集成到我的应用程序的 legacy 模块中,并在 uilding 时将 运行 集成到问题 IncompatibleComposeRuntimeVersionException 中。我想帮忙解决。

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

我一直在关注 official guide, and checked 寻求答案。我的应用程序的代码与官方 guide 非常匹配,相关的 SOpost 没有帮助。

这里是依赖项

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}",
],

项目中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'
    }
}

在应用程序、旧版和项目中 build.gradle

    buildFeatures {
        // Enables Jetpack Compose for this module
        compose true
    }

在 common-ui 模块中(在应用程序和遗留模块中实现)

    api libs.androidx.compose
    api libs.androidx.compose_activity

尝试将其添加到项目级别构建

buildscript {
    ext {
        compose_version = '1.0.1' //latest is 1.0.2 though (stable)
    }
}

解决方案是将 composeOptionsbuildFeaturescompileOptions 中的 Compose 设置代码移动到正在编写 Compose 代码的 legacy 模块中。官方文档指定了 app 模块,这并不总是准确的。

目前,您可以将 kotlin 版本更改为 1.5.21,以便与构建 gradle 项目级文件中的 jetpack compose 兼容。

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