compose和传统view的混合项目中编译报错。compse compiler
需要compose runtime
但是没有找到compose runtime
的class path。
androidx.compose.compiler.plugins.kotlin.IncompatibleComposeRuntimeVersionException:
The Compose Compiler requires the Compose Runtime to be on the class path, but none could be found.
The compose compiler plugin you are using (version 1.5.14) expects a minimum runtime version of 1.0.0.
遇事不决,先问AI。
感觉没毛病,没有runtime
我加个依赖不就行了。于是按照AI的回答增加依赖,修改kotlin版本,然后编译,不出意外是出意外了…
又报了这个错…说什么compose compiler 1.3.2
和kotlin 1.9.24
不兼容。
e: This version (1.3.2) of the Compose Compiler requires Kotlin version 1.7.20
but you appear to be using Kotlin version 1.9.24 which is not known to be compatible.
Please fix your configuration (or `suppressKotlinVersionCompatibilityCheck` but don't say I didn't warn you!).
可是我已经按照AI的回答,把compose comilper
改为1.5.14,koltin
改为1.9.22。这版本号对不上啊!!!于是怀疑是build缓存的问题,没办法了只能使用重启大法了,clean build、清除android studio缓存、重启。
不出意外的话又出意外了…还是不行。
又问了几遍AI,还是没有解决问题。AI解决不了,只有google了😢
最后在google compose的官方文档找到了原因。要把依赖放在app
模块的build.gradle
文件中。
原因
因为我是单独写一个模块来放compose相关的东西,没有写在app
模块模块里,所以出现了这个问题。项目结构如下。
解决方法
方法一:将compose
模块build.gradle
的依赖复制到app
模块的build.gradle
中。
方法二:直接将compose的implementation依赖改为api依赖也行。