模块之间的 Android Kotlin Compose 编译器版本不匹配

标签 android kotlin gradle gradle-plugin kotlin-gradle-plugin

我在我的应用中使用两个模块,一个用于 Android,一个用于 WearOS。这两个模块都使用 Jetpack Compose。

我可以使用 kotlin-gradle-plugin:1.7.20 毫无问题地构建 Android 模块。 如果我切换到 Wear 模块,AndroidStudio 会输出一条错误,指出它需要不同版本的 kotlin-gradle-plugin。这是我收到的错误:

This version (1.1.1) of the Compose Compiler requires Kotlin version 1.6.10 but you appear to be using Kotlin version 1.7.20 which is not known to be compatible.  Please fix your configuration (or `suppressKotlinVersionCompatibilityCheck` but don't say I didn't warn you!).

当然,我尝试将 Kotlin 版本降级到 1.6.10,但这在尝试构建任何模块时会带来完全不同的问题:

jetified-savedstate-ktx-1.2.1-api.jar!/META-INF/savedstate-ktx_release.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.6.0.

我在更改版本后尝试使缓存无效并重新启动

结论:

  • Android 模块需要版本 1.7.20
  • Wear 模块需要版本 1.6.10
  • 如果我降级,我会收到一个无法解决的不同错误

您将如何解决这个问题?据我所知,我无法在模块的基础上指定 kotlin-gradle-plugin 版本,它需要位于项目 gradle 文件中。我没有找到一种方法来为根文件中的依赖项指定模块,就像它是用 flavor 实现的一样。

最佳答案

Compose 编译器版本为 closely tied to kotlin version 。由于无法更改 kotlin 版本,因此需要更改 compose 编译器版本。现在是1.1.1,将其更改为1.3.2

注意:compose 编译器与 compose 不同。他们的版本是independent specifically for this reason .

关于模块之间的 Android Kotlin Compose 编译器版本不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76048839/

相关文章:

android - 在 android 中使用谷歌云存储 JSON api

java - 无法解析芬兰语言环境中的日期

android - 使用 Intent.putExtra 传递 Parcelable 数组

java - 是否可以在 Android 项目中运行最新版本的 Akka 框架(2.5.2)?

java - 带有 id 和 activity_main 的 kotlin 中未解析的引用

android - Robolectric 测试未运行 (Android)

android - fragment 中的 ArrayAdapter

java - 如何在 gradle 中设置库构建顺序?

Android:Gradle generateDebugSources 问题

java - gdx-支付 : "package com.badlogic.gdx.pay does not exist"