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

KMP iOS构建报错PhaseScriptExecution非零退出码,FirebaseFirestore模块未找到

故障排查与解决方案

报错本质

这是Kotlin Multiplatform iOS端cinterop阶段无法定位到FirebaseFirestore原生模块导致的构建失败,仅影响iOS端是因为Android侧不需要处理ObjC/Swift模块的绑定适配。

可按以下顺序排查解决:

  • 确认iOS侧依赖配置正确
    打开iOS项目目录下的Podfile,确认已添加pod 'FirebaseFirestore'依赖,且执行pod install后是通过.xcworkspace文件打开iOS项目,而非原始的.xcodeproj文件。
  • 检查shared模块的依赖配置
    如果是使用Kotlin官方CocoaPods插件管理iOS依赖,不需要手动编写cinterop配置,只需确认shared模块的cocoapods配置块中已声明pod("FirebaseFirestore")即可。
    如果是自行配置cinterop,需要确认iOS目标的build.gradle(.kts)配置包含正确的链接参数:
    示例配置(Kotlin MPP DSL):
    val iosMain by getting {
        compilations.getByName("main") {
            cinterops.create("FirebaseFirestore") {
                defFile = project.file("src/iosMain/cinterop/FirebaseFirestore.def")
                linkerOpts("-framework", "FirebaseFirestore", "-F${projectDir}/../ios/Pods/FirebaseFirestore/Frameworks")
            }
        }
    }
    
    同时检查对应.def文件是否正确声明了模块导入:
    language = Objective-C
    modules = FirebaseFirestore
    compilerOpts = -fmodules -fobjc-arc -I${projectDir}/../ios/Pods/Headers/Public
    
  • 版本对齐校验
    若使用KMP封装的Firebase依赖,需确保依赖声明的版本与iOS Podfile中FirebaseFirestore的版本完全一致,版本不匹配会导致模块无法被cinterop识别。
  • 全量清理缓存重试
    按以下顺序执行清理操作后重新构建:
    1. 进入iOS目录执行pod deintegrate && rm Podfile.lock && rm -rf Pods,再执行pod install
    2. 删除项目根目录下的.gradle文件夹、根目录build文件夹、shared模块下的build文件夹
    3. 重启IDE后重新执行iOS构建任务

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.04 05:06:03