compose编译失败(IncompatibleComposeRuntimeVersionException)

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.2kotlin 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依赖也行。
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值