简体   繁体   English

Xcode 11.4 编译错误'缺少 package 产品<package name> '</package>

[英]Xcode 11.4 compile error 'Missing package product <package name>'

When I integrate a local package in my Xcode project everything is fine initially but when i switch branches and want to run the app Xcode gives me the compile error Missing package product <package name> . When I integrate a local package in my Xcode project everything is fine initially but when i switch branches and want to run the app Xcode gives me the compile error Missing package product <package name> . When I quit Xcode and re-open it everything is fine again.当我退出 Xcode 并重新打开它时,一切都很好了。 Any idea what this can be?知道这可能是什么吗? An Xcode bug? Xcode 错误?

We also integrate external packages via Swift Package Manager which works perfectly fine.我们还通过 Swift Package 管理器集成外部软件包,该管理器运行良好。 No issues there.那里没有问题。

The issue is also well described in a post by Jesse Squires . Jesse Squires 在一篇文章中也很好地描述了这个问题。

Solution 1: File > Swift Packages > Reset Package Caches解决方案 1:文件 > Swift 包 > 重置包缓存

在此处输入图像描述

Solution 2: File > Swift Packages > Update to Latest Package Versions解决方案 2:文件 > Swift 包 > 更新到最新包版​​本

在此处输入图像描述

对我来说,我需要 File > Swift Packages > Reset Package Caches

In Xcode go to File > Swift Packages > Update to Latest Package Versions在 Xcode 中,转到 File > Swift Packages > Update to Latest Package Versions

Worked for me为我工作

In Xcode go to Product > Clean Build Folder在 Xcode 中,转到Product > Clean Build Folder

This worked for me.这对我有用。 The problem originally started when I was trying to solve another issue that came up after I deleted my Derived Data folder.该问题最初是在我尝试解决删除派生数据文件夹后出现的另一个问题时开始的。

Restarting Xcode didn't work, but cleaning the build folder did.重新启动 Xcode 不起作用,但清理构建文件夹可以。 I don't know if the other answers here would work for me because I didn't try them seeing as cleaning the build folder worked.我不知道这里的其他答案是否对我有用,因为我没有尝试将它们视为清理构建文件夹有效。

I bumped into this issue today on Xcode 13.0 when working on the WooCommerce iOS app after manually deleting the DerivedData folder.今天在手动删除DerivedData文件夹后,我在使用WooCommerce iOS 应用程序时在 Xcode 13.0 上遇到了这个问题。

The build was failing like in the questions description: Missing package product '<package name>'构建失败,就像问题描述中一样: Missing package product '<package name>'

Xcode 中构建失败的屏幕截图

I tried both resetting the packages cache and updating to the latest versions, but neither work.我尝试了重置包缓存和更新到最新版本,但都不起作用。 Thinking about it, that's not surprising since the packages Xcode couldn't find were local packages .想想看,这并不奇怪,因为 Xcode 找不到的包是本地包

What did the trick for me was following this suggestion from an Apple forums thread and remove the local packages references, then adding them back again.对我来说,诀窍是遵循 Apple 论坛线程中的这个建议删除本地包引用,然后再次添加它们。

In WooCommerce's case, the local packages are part of a workspace file.在 WooCommerce 的案例中,本地包是工作区文件的一部分。 Removing then adding them back again in the same order didn't result in a diff in the file.删除然后以相同的顺序再次添加它们不会导致文件中的差异。 That is, nothing really changed in the workspace setup, but that was apparently the kind of kick Xcode needed to get over that error.也就是说,工作区设置并没有真正改变,但这显然是 Xcode 克服该错误所需的那种踢。 🤷‍♂️ 🤷‍♂️

None of the answers worked for me on Xcode 12.5 beta.在 Xcode 12.5 beta 上,没有一个答案对我有用。 I had to manually remove all spm packages and re add them.我不得不手动删除所有 spm 包并重新添加它们。

I'm not sure of the root cause, but I get this quite regularly.我不确定根本原因,但我经常得到这个。 Not the most elegant solution, but neither Reset Package Caches nor Update to Latest Package Versions worked for me.不是最优雅的解决方案,但重置包缓存和更新到最新包版​​本都不适合我。 For me, I had to quit Xcode, and delete DerivedData.对我来说,我不得不退出 Xcode,并删除 DerivedData。

rm -rf ~/Library/Developer/Xcode/DerivedData/*

Then rebuild.然后重建。

SPM - Reset Package Caches vs Update to Latest Package Versions SPM - 重置包缓存与更新到最新包版​​本

File -> Swift Packages -> Reset Package Caches  
File -> Swift Packages -> Update to Latest Package Versions 

Update to Latest Package Versions更新到最新的软件包版本

fetch the latest possible version(based on restrictions)

Reset Package Caches重置包缓存

reset cache(derived folder) -> Update to Latest Package Versions 

folder文件夹

<path_to_derived_data>/<randomizer>/SourcePackages/checkouts/<project_name>
//e.g
/Users/alex/Library/Developer/Xcode/DerivedData/SPM-dpsmlyjrashqjefkfheppizcrgic/SourcePackages/checkouts/SPMExperiments

[Local SPM] [本地 SPM]

A workaround for me at the moment has been both running Product > Clean Build Folder (cmd-k) and then restarting Xcode.目前对我来说一个解决方法是运行 Product > Clean Build Folder (cmd-k) 然后重新启动 Xcode。 This is an issue in both Xcode 12.4 and 12.5, and 12.5's per user package caching did not resolve the issue.这是 Xcode 12.4 和 12.5 中的一个问题,并且 12.5 的每个用户包缓存没有解决这个问题。

File > Swift Packages > Reset Package Caches also appears to work but it is slower for me. File > Swift Packages > Reset Package Caches 似乎也可以工作,但对我来说速度较慢。

Context:语境:

One of my vendors distributes their pre-compiled binary library via SPM.我的一个供应商通过 SPM 分发他们的预编译二进制库。 Whenever I switch between git development branches, I get:每当我在 git 开发分支之间切换时,我都会得到:

"artifact of binary target 'xyz' failed extraction: The operation couldn't be completed. (TSCBasic.StringError error 1.)" “二进制目标‘xyz’提取失败的工件:操作无法完成。(TSCBasic.StringError 错误 1。)”

It also causes these "missing package product" errors for totally unrelated packages presumably because if one package fails the whole SPM process fails ("resolving package graph failed") even if these package are entirely independent.对于完全不相关的包,它也会导致这些“缺少包产品”错误,大概是因为如果一个包失败,整个 SPM 过程就会失败(“解析包图失败”),即使这些包是完全独立的。

Edit: With Xcode 12.5 simply quitting Xcode and re-opening seems to be enough.编辑:使用 Xcode 12.5 只需退出 Xcode 并重新打开似乎就足够了。

I got this error when having the same local Swift package open in two different instances of Xcode in two different projects.当在两个不同项目的两个不同 Xcode 实例中打开相同的本地 Swift 包时,我收到此错误。 Got it working again by quitting Xcode and only having one project open at a time.通过退出 Xcode 并一次只打开一个项目使其再次工作。

Xcode Source Control should be enabled to run this.应该启用 Xcode Source Control 来运行它。 Preference -> Source Control and enable the source control. Preference -> Source Control并启用源代码控制。

Just a silly question: did you set up your git account on Xcode preferences?只是一个愚蠢的问题:您是否在 Xcode 首选项中设置了您的 git 帐户?

在此处输入图像描述

Start with the other answers like从其他答案开始,例如

  • Reset Package Caches重置包缓存
  • Product > Clean Build Folder产品 > 清洁构建文件夹

If this doesn't help...如果这没有帮助...

In my messages I found a hint that I had a dependency to two different version of the same package.在我的消息中,我发现我对同一个包的两个不同版本有依赖关系。

After fixing this, Reset Package Caches suddenly worked for most of my packages.修复此问题后,Reset Package Caches 突然对我的大多数包都有效。

I could fix the remaining problems by adding我可以通过添加来解决剩余的问题

platforms: [
    .iOS(.v13),
],

to the corresponding package.到相应的包。 Before that, I had no platforms statement.在此之前,我没有platforms声明。

I had some packages that were part of my project but would intermittently fail to build.我有一些包是我项目的一部分,但会间歇性地无法构建。

I found that specifying the path to the Sources and Tests folders resolved the issue:我发现指定SourcesTests文件夹的路径解决了这个问题:

targets: [
        .target(
            name: "MyInternalPackage",
            dependencies: [],
            path: "Sources"), // <<<<<< Even tho this is the default, sometimes get build errors without it
        .testTarget(
            name: "MyInternalPackageTests",
            dependencies: ["MyInternalPackage"],
            path: "Tests") // <<<<<< Even tho this is the default, sometimes get build errors without it
    ]

在项目中的当前分支重命名后我遇到了这个问题,并通过清除工作区中的 xcuserdata 来解决它。

If none of the above answers work, Please refer the solution shared by GravityBytes in this link on Apple Forums.如果以上答案均无效,请参考 GravityBytes 在 Apple 论坛的此链接中分享的解决方案。

Eventually he happened to share the below resolution最终他碰巧分享了以下决议

I eventually got this resolved.我最终解决了这个问题。 What seemed to get it working was re-adding my local packages using the "Add Packages…" menu option on the project that has the framework targets using the local package.似乎让它工作的是在项目上使用“添加包...”菜单选项重新添加我的本地包,该项目具有使用本地包的框架目标。 This created a new "Packages" group in the project, and eventually started compiling correctly.这在项目中创建了一个新的“Packages”组,并最终开始正确编译。

Please remove the existing references and try adding them using the above approach.请删除现有引用并尝试使用上述方法添加它们。

For Moya I had to edit project file to Xcode heart's content对于 Moya,我必须将项目文件编辑为 Xcode heart 的内容

/* XCRemoteSwiftPackageReference "Moya" */ = {
                    isa = XCRemoteSwiftPackageReference;
                    repositoryURL = "https://github.com/Moya/Moya";
                    requirement = {
                            kind = upToNextMajorVersion;
                            minimumVersion = 13.0.2;
                    };

anything other than 13.0.2 results in unresolutio for the numerous semicircular dependencies that Moya package brings to the table. 13.0.2 以外的任何版本都会导致 Moya 包带来的众多半圆形依赖项无法解决。

This breathes a new life into https://foldoc.org/field+circus这为https://foldoc.org/field+circus注入了新的活力

除了Product -> Clean Build Folder and Restart对我没有任何帮助

I tried:我试过了:

  • Clean project清洁项目
  • Clean derived data清理派生数据
  • Resolve Package Versions (File > Package)解决 Package 版本(文件 > 包)
  • Update to Latest Package Versions (File > Package)更新到最新 Package 版本(文件 > 包)
  • Restart Xcode重启Xcode
  • Restart Mac重启 Mac

And restarting the Mac is what worked重新启动 Mac 是有效的

Others say doing "Resolve Package Versions" multiple times also work.其他人说多次执行“解决 Package 版本”也可以。

For me, Xcode was opened using Rosetta which wans't enabled before.对我来说,Xcode 是使用以前无法启用的 Rosetta 打开的。 Re-disable open using Rosetta helped me使用 Rosetta 重新禁用打开对我有帮助

In Xcode 12.0.1 (12A7300) this bug has been fixed.在 Xcode 12.0.1 (12A7300) 中,此错误已得到修复。 It was auto-resolved by the Xcode update for me. Xcode 更新为我自动解决了这个问题。

EDIT Xcode 12.5 [beta]编辑 Xcode 12.5 [测试版]

Apple added a SPM cache. Apple 添加了 SPM 缓存。 See my question here . 在这里查看我的问题 If you run into this problem with this Xcode version it might help to delete this cache.如果您在使用此 Xcode 版本时遇到此问题,删除此缓存可能会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM