Android Compose使用最新Material库时CircularProgressIndicator崩溃求助
问题分析
崩溃日志抛出java.lang.NoSuchMethodError,找不到androidx.compose.animation.core.KeyframesSpec$KeyframesSpecConfig.at()方法,核心原因是Compose与Kotlin依赖版本不兼容:
- 顶层Gradle中Kotlin版本为1.9.22,但App模块内引用的Kotlin BOM是1.8.0,版本不匹配
- 同时混用Compose BOM(2023.10.01)与单独指定版本的Compose库(如
material:1.6.0-rc01、runtime-livedata:1.6.0-rc01),导致依赖版本冲突,出现方法缺失
解决方案
统一所有Compose与Kotlin相关依赖版本,优先通过BOM管理版本,避免单独指定版本:
1. 保持顶层build.gradle配置
buildscript { ext.kotlin_version = '1.9.22' ext.compose_version = '1.5.8' }
2. 修正app/build.gradle依赖配置
- 将Kotlin BOM版本改为与顶层一致的1.9.22
- 移除所有单独指定版本的Compose库,完全依赖Compose BOM管理版本
- 保留非Compose类依赖(如
lifecycle-runtime-compose、constraintlayout-compose)
修改后的依赖代码:
// compose implementation platform('org.jetbrains.kotlin:kotlin-bom:1.9.22') implementation platform('androidx.compose:compose-bom:2023.10.01') implementation 'androidx.compose.ui:ui' implementation 'androidx.compose.ui:ui-graphics' implementation 'androidx.compose.ui:ui-tooling-preview' implementation 'androidx.lifecycle:lifecycle-runtime-compose' implementation 'androidx.compose.material:material' implementation 'androidx.compose.material3:material3' implementation 'androidx.compose.runtime:runtime-livedata' implementation "androidx.constraintlayout:constraintlayout-compose:1.1.0-alpha13" debugImplementation 'androidx.compose.ui:ui-tooling' debugImplementation 'androidx.compose.ui:ui-test-manifest'
3. 同步并重建项目
- 执行
File -> Sync Project with Gradle Files - 执行
Build -> Clean Project后再执行Build -> Rebuild Project
原理说明
Compose BOM会自动维护所有Compose库的兼容版本,混用BOM与单独指定版本会导致不同库版本不匹配,引发方法缺失、类找不到等崩溃。同时Kotlin版本必须与Compose版本兼容,1.9.22版本的Kotlin与Compose 1.5.x系列、指定的2023.10.01版本BOM完全兼容。
内容的提问来源于stack exchange,提问作者rosu alin
相关产品推荐
相关产品推荐

