xcode 构建失败,“命令失败,退出代码非零”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/46690619/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 18:28:30  来源:igfitidea点击:

Build fails with "Command failed with a nonzero exit code"

xcode

提问by Tamás Sengel

When I try to build my app with Xcode, an error interrupts the build process:

当我尝试使用 Xcode 构建我的应用程序时,一个错误会中断构建过程:

Command CompileStoryboardfailed with a nonzero exit code

命令CompileStoryboard失败,退出代码非零

Sometimes, it shows this error instead:

有时,它会显示此错误:

Command CompileSwiftfailed with a nonzero exit code

命令CompileSwift失败,退出代码非零

I have New Build Systemturned on.

我打开了新构建系统

What can I do to fix this?

我能做些什么来解决这个问题?

回答by George_E

Closing Xcode for me didn't have an effect. Instead, I cleaned the project using CommandShiftK.

为我关闭 Xcode 没有效果。相反,我使用CommandShiftK.



I also found another reason: I had a storyboard reference to another storyboard which I had removed. The quick fix was deleting this.

我还发现了另一个原因:我有一个故事板引用了另一个我已删除的故事板。快速修复是删除它。

enter image description here

enter image description here

回答by Tamás Sengel

When you stop building a project when the compiler is in the middle of something "important", this error could appear. In that case, building the project againand letting it finish normally makes this error disappear.

当编译器处于“重要”状态时停止构建项目时,可能会出现此错误。在这种情况下,再次构建项目并让它正常完成会使此错误消失。

回答by cdeerinck

This is a known issue with Swift 4.2 and Xcode 10. I found an article here that fixed it for me: https://github.com/Yummypets/YPImagePicker/issues/236

这是 Swift 4.2 和 Xcode 10 的一个已知问题。我在这里找到了一篇为我修复的文章:https: //github.com/Yummypets/YPImagePicker/issues/236

In short, go to your projects build settings, and add a user defined setting named SWIFT_ENABLE_BATCH_MODE and set its value to NO.

简而言之,转到您的项目构建设置,并添加一个名为 SWIFT_ENABLE_BATCH_MODE 的用户定义设置并将其值设置为 NO。

Previously, I tried each of the methods suggested here (rebuild, exit Xcode, clean and rebuild, purge Derived Data files). None of them worked.

以前,我尝试了这里建议的每种方法(重建、退出 Xcode、清理和重建、清除派生数据文件)。他们都没有工作。

Once I added the user define build setting per the article, Swift then told me the true error. In my case, it was a missing }, but it could be any number of problems.

一旦我根据文章添加了用户定义构建设置,Swift 就会告诉我真正的错误。在我的情况下,它是一个缺失的},但它可能是任何数量的问题。

回答by Krishna Meena

I also facing same issue in xcode 10 and tried all the solutions provided but nothing working.

我在 xcode 10 中也面临同样的问题,并尝试了所有提供的解决方案,但没有任何效果。

Then I deleted all the files and folders of the following folder :

然后我删除了以下文件夹的所有文件和文件夹:

/Users/meenakrishna/Library/Developer/Xcode/DerivedData

and it worked like a charm.

它就像一个魅力。

回答by JeffreyWang23

This error happened to me when I forgot to change entity Properties before creating NSManagedObject subclass. Solved by:

当我在创建 NSManagedObject 子类之前忘记更改实体属性时,发生了这个错误。解决者:

  1. delete Entity+CoreDataClass.swiftand Entity+CoreDataProperties.swift.
  2. under "class" of the entity model inspector, change "module" to Current Product Moduleand "codegen" to Manual/None.
  3. recreate the NSManagedObject.
  1. 删除Entity+CoreDataClass.swiftEntity+CoreDataProperties.swift
  2. 在实体模型检查器的“类”下,将“模块”更改为,将“代码生成”更改Current Product ModuleManual/None.
  3. 重新创建 NSManagedObject。

image

image

回答by Benj

I had the error Command LinkStoryboards failed with a nonzero exit code, and found that I was using a reference to a non-existent storyboard. I had recently changed the name of a storyboard file, so changing the reference from the 'old' name to the 'new' name solved it for me.
You may not have exactly the same error as me, but an easy way to find a more detailed explanation of the error is to:

我遇到了错误Command LinkStoryboards failed with a nonzero exit code,发现我使用了对不存在的故事板的引用。我最近更改了故事板文件的名称,因此将引用从“旧”名称更改为“新”名称为我解决了这个问题。
您可能没有与我完全相同的错误,但是找到更详细的错误解释的简单方法是:

  • Show the issue navigator (while the build time error is showing)
  • Click the error: Click the error in the issue navigator
  • Then, you should see more about your error: Command LinkStoryboards failed with nonzero exit code
  • 显示问题导航器(同时显示构建时间错误)
  • 点击错误: Click the error in the issue navigator
  • 然后,您应该会看到有关错误的更多信息: Command LinkStoryboards failed with nonzero exit code


I hope this helps. Please, I am aware that I am answering from experience of a different error than this question was asked about, but I believe this advice should help you conquer similar problems!


我希望这有帮助。拜托,我知道我是根据与这个问题不同的错误经验来回答的,但我相信这个建议应该可以帮助你克服类似的问题!

回答by Mostafa Al Belliehy

I encountered this error when I was upgrading my project from Swift 4 to 5. I first updated all my pods to their latest versions. When I built, some pods showed this error.

当我将我的项目从 Swift 4 升级到 5 时遇到了这个错误。我首先将我的所有 pod 更新到了它们的最新版本。当我构建时,一些 pod 显示了这个错误。

The following steps resolved this issue for me:

以下步骤为我解决了这个问题:

  1. Removed all pods from Podfile
  2. Executed pod installto remove all installed pods
  3. Executed pod deintegrateto remove support for CocoaPods
  4. Deleted Podfile.lockand .xcworkspacefrom my project so no CocoaPods anymore
  5. Now my project is a pure Xcode project
  6. Opened my project from the regular .xcodeprojfile
  7. Changed Swift Version of my project to Swift 5
  8. Cleaned the project (cmd+shift+K)
  9. Quitted Xcode
  10. Restored all pods to my Podfile
  11. Executed pod installto reintegrate CocoaPods and add my pods
  12. Opened the project from the .xcworkspacefile
  13. Cleaned and rebuilt
  14. Some old pods that were still using Swift 4.0 (SlideMenuControllerSwift in my case) were set to Swift 5.0, caused many build errors in their code. I corrected it back to Swift 4.0 by opening the Pods project and selecting its target.
  15. Cleaned again, rebuilt.
  1. 删除了所有的豆荚 Podfile
  2. 执行pod install以删除所有已安装的 pod
  3. 执行pod deintegrate以删除对 CocoaPods 的支持
  4. 已从我的项目中删除Podfile.lock.xcworkspace因此不再有 CocoaPods
  5. 现在我的项目是一个纯 Xcode 项目
  6. 从常规.xcodeproj文件打开我的项目
  7. 将我的项目的 Swift 版本更改为 Swift 5
  8. 清理项目(cmd+shift+K)
  9. 退出 Xcode
  10. 将所有豆荚恢复到我的 Podfile
  11. 执行pod install重新集成 CocoaPods 并添加我的 Pod
  12. .xcworkspace文件中打开项目
  13. 清理和重建
  14. 一些仍在使用 Swift 4.0(在我的例子中是 SlideMenuControllerSwift)的旧 pod 被设置为 Swift 5.0,导致它们的代码中出现许多构建错误。我通过打开 Pods 项目并选择其目标将其更正为 Swift 4.0。
  15. 再次清洗,重建。

Now I have only errors in my own project code related with difference in Swift version I made. My job now is to fix them.

现在,我自己的项目代码中只有与我制作的 Swift 版本差异相关的错误。我现在的工作是修复它们。

回答by Adam Bardon

If you have multiple targets, where two or more targets have files with the same name, check the target membership of those files in Files inspector. The error occurs when multiple instances of the equally named file have set the target membership for the same target.

如果您有多个目标,其中两个或多个目标具有相同名称的文件,请在文件检查器中检查这些文件的目标成员资格。当同名文件的多个实例为同一目标设置了目标成员资格时,就会发生该错误。

回答by Charlton Provatas

Switching to the legacy build system fixed the issue for me

切换到旧版构建系统为我解决了这个问题

回答by Steve E

Since this issue looks to have dozens of possible solutions and the root cause could be very vague, I'll throw my situation into the ring. Half of my pods were failing with some sort of CompileSwiftSourcefailure, but only on archive. I was still able to build for device and simulator just fine. I tried a lot (if not all) of the solutions suggested here with no luck. One of the pods had a slightly different error before the CompileSwiftSourceerror so I went to updating and trying to fix that single pod. It was the Cachelibrary for iOS which hadn't been updated in a while. There was a fork that resolved the issue with updating to Xcode 10.2 that I was able to update to and after that, all of the other issues took care of themselves. So look for a single outlier in your pods if you're getting a bunch of them erroring out and start there.

由于这个问题看起来有几十种可能的解决方案,而且根本原因可能非常模糊,我将把我的情况抛诸脑后。我的一半 pod 因某种CompileSwiftSource故障而失败,但仅限于存档。我仍然能够很好地为设备和模拟器构建。我尝试了很多(如果不是全部)这里建议的解决方案,但没有成功。其中一个 Pod 在出现错误之前有一个略有不同的CompileSwiftSource错误,所以我去更新并尝试修复那个单个 Pod。这是CacheiOS的库,有一段时间没有更新。有一个 fork 解决了更新到 Xcode 10.2 的问题,我可以更新到该问题,之后所有其他问题都解决了。因此,如果您的 pod 中出现一堆错误并从那里开始,请在您的 pod 中寻找一个异常值。