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

Xcode14.3/15下Fastlane集成Slather报错:找不到Coverage.profdata

Fastlane集成Slather无法找到代码覆盖文件夹的问题解决思路

问题背景

配置在Xcode 14.2环境下可正常运行,升级到Xcode14.3.x或Xcode15后,Fastlane集成Slather时出现报错,提示无法找到代码覆盖文件夹。

Fastlane配置代码

slather(
      build_directory: "./DerivedData",
      scheme: "MyApp",
      workspace: "MyApp.xcworkspace",
      proj: "./MyApp.xcodeproj",
      output_directory: "./DerivedData/testResult", 
      cobertura_xml: true,
      verbose: true
)     

错误信息

Exit status of command 'slather coverage --cobertura-xml --build-directory ./DerivedData --output-directory ./DerivedData/test-output/slatherOutput --ignore Pods/* --ignore fastlane/* --ignore build/* --ignore DerivedData/* --verbose --scheme ProjectName --workspace ProjectName.xcworkspace ./ProjectName.xcodeproj' was 1 instead of 0.

Slathering...
/usr/local/lib/ruby/gems/3.0.0/gems/slather-2.7.4/lib/slather/project.rb:239:in `profdata_coverage_dir': No coverage directory found. (StandardError)
    from /usr/local/lib/ruby/gems/3.0.0/gems/slather-2.7.4/lib/slather/project.rb:517:in `find_binary_files'
    from /usr/local/lib/ruby/gems/3.0.0/gems/slather-2.7.4/lib/slather/project.rb:336:in `configure'
    from /usr/local/lib/ruby/gems/3.0.0/gems/slather-2.7.4/lib/slather/command/coverage_command.rb:59:in `execute'
    from /usr/local/lib/ruby/gems/3.0.0/gems/clamp-1.3.2/lib/clamp/command.rb:66:in `run'
    from /usr/local/lib/ruby/gems/3.0.0/gems/clamp-1.3.2/lib/clamp/subcommand/execution.rb:18:in `execute'
    from /usr/local/lib/ruby/gems/3.0.0/gems/clamp-1.3.2/lib/clamp/command.rb:66:in `run'
    from /usr/local/lib/ruby/gems/3.0.0/gems/clamp-1.3.2/lib/clamp/command.rb:140:in `run'
    from /usr/local/lib/ruby/gems/3.0.0/gems/slather-2.7.4/bin/slather:17:in `<top (required)>'
    from /usr/local/lib/ruby/gems/3.0.0/bin/slather:25:in `load'
    from /usr/local/lib/ruby/gems/3.0.0/bin/slather:25:in `<main>'
No coverage directory found.

    Are you sure your project is generating coverage? Make sure you enable code coverage in the Test section of your Xcode scheme.
    Did you specify your Xcode scheme? (--scheme or 'scheme' in .slather.yml)
    If you're using a workspace, did you specify it? (--workspace or 'workspace' in .slather.yml)
    If you use a different Xcode configuration, did you specify it? (--configuration or 'configuration' in .slather.yml)

不同Xcode版本的表现

Xcode 14.2正常日志

Processing coverage file: /Users/runner/work/repo/repo/DerivedData/Build/ProfileData/C9A-EA9C-4732-A6CD-ED50D/Coverage.profdata

Xcode14.3.x或Xcode15错误日志

/usr/local/lib/ruby/gems/3.0.0/gems/slather-2.7.5/lib/slather/project.rb:239:in `profdata_coverage_dir': No coverage directory found. (StandardError)

解决思路

  • 适配Xcode 14.3+的Coverage文件路径变化
    Xcode14.3之后,Coverage.profdata的路径从DerivedData/Build/ProfileData/<UUID>/变更为DerivedData/Build/ProfileData/<UUID>/Coverage/,旧版本Slather未适配该路径。可通过两种方式处理:

    1. 在Fastlane的slather配置中添加profdata_path参数,直接指向生成的文件:
      slather(
        build_directory: "./DerivedData",
        scheme: "MyApp",
        workspace: "MyApp.xcworkspace",
        proj: "./MyApp.xcodeproj",
        output_directory: "./DerivedData/testResult", 
        cobertura_xml: true,
        verbose: true,
        profdata_path: "./DerivedData/Build/ProfileData/<UUID>/Coverage/Coverage.profdata"
      )
      
    2. 用脚本动态获取最新路径,比如:
      PROFDATA_PATH=$(find ./DerivedData -name "Coverage.profdata" | head -1)
      
      再在Fastlane中引用该变量。
  • 升级Slather到适配版本
    执行gem update slather升级到最新版,部分新版本已修复Xcode路径变更的适配问题。

  • 确认Xcode Scheme配置
    打开Scheme编辑窗口 → Test → Options,确保勾选了"Code Coverage"(可选择"Gather coverage for all targets"或指定目标)。

  • 检查Fastlane执行顺序
    确保Slather在测试任务(如scan)执行完成后运行,避免测试后清理DerivedData导致文件丢失。

  • 调整Slather的ignore规则
    错误信息显示Slather忽略了DerivedData/*,这会阻止它扫描Coverage文件,需修改规则:去掉--ignore DerivedData/*,或精确忽略不需要的子目录,保留Build/ProfileData路径。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.09 12:58:16