You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Compose Multiplatform使用CupertinoTimePicker遇NoSuchMethodError问题求助

修复Compose Multiplatform中CupertinoTimePicker的NoSuchMethodError错误

问题根源

这个错误是因为你使用的Cupertino Compose库版本与Compose Multiplatform 1.7.x不兼容。Compose 1.7.x对rememberSnapFlingBehavior方法的签名做了调整,而旧版Cupertino库仍在调用旧签名的方法,导致运行时找不到该方法。

修复步骤

1. 升级Cupertino Compose库到适配版本

需要将Cupertino库升级到0.6.0及以上版本(该版本开始适配Compose Multiplatform 1.7.x):

  • 如果使用libs.versions.toml管理版本,修改配置:
    [versions]
    cupertino = "0.6.0"
    
  • 或者直接在commonMain的依赖中指定版本:
    commonMain.dependencies {
        // 替换旧的Cupertino依赖为适配版本
        implementation("io.github.alexzhirkevich:cupertino:0.6.0")
        implementation("io.github.alexzhirkevich:cupertino-adaptive:0.6.0")
        implementation("io.github.alexzhirkevich:cupertino-native:0.6.0")
        implementation("io.github.alexzhirkevich:cupertino-icons-extended:0.6.0")
    }
    

2. 清理缓存并重新构建项目

执行以下Gradle命令消除缓存中的旧依赖:

./gradlew clean
./gradlew assembleDebug

3. 检查并解决依赖冲突(可选)

如果升级后仍有问题,检查是否存在Compose Foundation库的版本冲突:

  • 运行命令查看依赖树:
    ./gradlew androidDependencies
    
  • 若发现foundation版本不一致,强制统一为Compose 1.7.3对应的版本:
    commonMain.dependencies {
        implementation(libs.compose.foundation) {
            force = true
        }
    }
    

验证

完成上述步骤后,重新运行项目,CupertinoTimePicker应该能正常加载,不会再触发NoSuchMethodError。

内容的提问来源于stack exchange,提问作者Ashaluwala Kazeem

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 10:28:22