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

XcodeGen引入本地Swift Package时出现"Missing package product"错误(指向xcodeproj而非包目录)

XcodeGen引入本地Swift Package时出现"Missing package product"错误(指向xcodeproj而非包目录)

Hey there, let's work through this XcodeGen + Swift Package Manager issue you're hitting. From what you shared, you're trying to pull in a local Swift Package called 'Core' into your XcodeGen-generated project, but Xcode can't resolve it correctly—plus it seems like it's pointing to the .xcodeproj instead of the actual package directory, right? You mentioned using Cursor IDE to build the project too, so let's break this down step by step.

First, let's recap what you've already confirmed:

  • Your project.yml includes the Core package definition, and the Package.swift at the specified path is valid
  • When you right-click the Core entry in "Frameworks, Libraries, and Embedded Content", there's an issue (sounds like it's linking to the wrong location or failing to find the package product)

Common Fixes to Try:

  1. Double-check your project.yml package reference
    Make sure you're pointing directly to the folder containing the Package.swift (not the .xcodeproj) in your project.yml. The correct setup should look like this:

    packages:
      Core:
        path: ./Core # 指向包含Package.swift的目录,不是Core.xcodeproj
    

    Then, in your target dependencies, confirm you're referencing the exact product name from the Core package:

    targets:
      MyAppTarget:
        dependencies:
          - package: Core
            product: Core # 必须和Package.swift里定义的product名称一致
    
  2. Clear Xcode's Derived Data
    Xcode loves hanging onto old cache, which often causes weird package resolution glitches. Head to Xcode > Settings > Locations, click the arrow next to Derived Data to open the folder, then delete everything inside. Restart Xcode, then regenerate your project with xcodegen generate.

  3. Validate your Core package's Package.swift
    Make sure the Package.swift for your Core package defines a product that matches what you're referencing in project.yml. For example:

    let package = Package(
        name: "Core",
        products: [
            .library(
                name: "Core", // 这个名称要和project.yml里的product字段完全匹配
                targets: ["Core"]),
        ],
        targets: [
            .target(name: "Core"),
        ]
    )
    
  4. Regenerate your project from scratch
    Stale generated files can cause issues. Run xcodegen clean first to delete the existing .xcodeproj, then run xcodegen generate again to create a fresh project. Open the new project and check if the Core package resolves properly.

  5. Sync Cursor IDE with the updated project
    Since you're using Cursor, make sure it's synced with the latest generated project. Try closing and reopening Cursor, or refreshing the project structure. IDEs can sometimes hold onto old cache that doesn't reflect the latest XcodeGen changes.

If None of the Above Work:

  • Try manually adding the Core package to Xcode via File > Add Packages > Add Local.... If this works, compare the manual setup with what XcodeGen generated to spot any discrepancies in references.
  • Double-check for typos in paths, package names, or product names—small mistakes here are super common and easy to miss!

备注:内容来源于stack exchange,提问作者Dario

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.13 16:33:18