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

GitHub Actions中用xcodebuild结合OpenAPIGenerator Plugin跑iOS测试报错

解决OpenAPIGenerator Plugin导致的_OpenAPIGeneratorCore链接错误

问题本质

错误提示_OpenAPIGeneratorCore is only to be used by swift-openapi-generator itself-your target should not link this library or the command line tool directly,说明你的业务target直接链接了swift-openapi-generator的内部核心库,而该库仅供插件内部使用,不允许业务代码直接依赖。

解决步骤

1. 修正依赖配置

根据你使用的依赖管理工具调整配置:

  • CocoaPods:检查Podfile,确保仅引入swift-openapi-generator插件,不要直接添加_OpenAPIGeneratorCore作为pod依赖。正确配置示例:

    plugin 'swift-openapi-generator', {
      input: 'openapi.yaml', # 你的OpenAPI定义文件路径
      output: './Generated'  # 生成代码的输出路径
    }
    

    执行pod deintegrate && pod install重新安装依赖。

  • Swift Package Manager:在Package.swift中,确保swift-openapi-generator仅作为target的plugin依赖,而非普通依赖。示例:

    dependencies: [
      .package(url: "https://github.com/apple/swift-openapi-generator.git", from: "1.0.0")
    ],
    targets: [
      .target(
        name: "AppName",
        plugins: [
          .plugin(name: "OpenAPIGeneratorPlugin", package: "swift-openapi-generator")
        ]
      )
    ]
    

2. 清理项目缓存

  • 本地清理:
    rm -rf DerivedData
    rm -rf ~/Library/Caches/org.swift.swiftpm
    
  • GitHub Actions中添加清理步骤,避免缓存干扰:
    - name: Clean project artifacts
      run: |
        xcodebuild clean -scheme AppName -project AppName.xcodeproj
        rm -rf ~/Library/Caches/org.swift.swiftpm
    

3. 检查Xcode Target配置

打开Xcode项目,进入App target的配置页面:

  • 进入Build Phases > Link Binary With Libraries,若存在_OpenAPIGeneratorCore,直接移除。
  • 检查Build Settings > OTHER_LDFLAGS,确保没有手动添加链接_OpenAPIGeneratorCore的参数。

4. 验证本地构建

先在本地执行你的xcodebuild测试命令,确认构建和测试正常后,再推送代码到GitHub Actions运行。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.07 00:54:56