ios Xcode 10 构建失败,“Command CompileSwift failed with a nonzero exit code

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/52415877/
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-08-31 09:48:30  来源:igfitidea点击:

Xcode 10 build fails with 'Command CompileSwift failed with a nonzero exit code

iosswiftxcode10swiftmessages

提问by Spencer Shelton

I updated Xcode to version 10 recently and started to receive a strange error when trying to build my project. I'm currently on Swift 4.0 and I did try to upgrade to swift Version 4.2. But when I did I received this same error in many of my frameworks.

我最近将 Xcode 更新到版本 10,并在尝试构建我的项目时开始收到一个奇怪的错误。我目前使用的是 Swift 4.0,我确实尝试升级到 Swift 4.2 版。但是当我这样做时,我在许多框架中都收到了同样的错误。

Command Compile Swift failed with a nonzero exit code

命令编译 Swift 失败,退出代码非零

So far I've deleted the derived folder. Updated all pods, also deleted all pods and reinstalled them using the terminal commands below.

到目前为止,我已经删除了派生文件夹。更新了所有 pod,也删除了所有 pod 并使用下面的终端命令重新安装了它们。

sudo gem install cocoapods-deintegrate cocoapods-clean
pod deintegrate
pod clean
pod install

This didn't work to fix my issue. However, I found something that could work which was adding arm64architecture in Build Setting -> valid architecturesand enabling automatic code But, when I checked it was already there and code signing was enabled already.

这并不能解决我的问题。但是,我发现了一些可行的方法,即arm64在其中添加架构Build Setting -> valid architectures并启用自动代码但是,当我检查它时,它已经存在并且已经启用了代码签名。

Additionally, I do have a few other build errors that have to do with frameworks.

此外,我还有其他一些与框架有关的构建错误。

SwiftMessages

迅捷消息

Value of type 'SwiftMessages.Config' has no member 'presentationContext'

'SwiftMessages.Config' 类型的值没有成员 'presentationContext'

WhatsNewKit

什么是新套件

Missing argument for parameter 'backgroundColor' in call`

调用中缺少参数“backgroundColor”的参数

I opened issues with the developers of each of these frameworks to seek help with these issues.

我向这些框架的开发人员提出了问题,以寻求解决这些问题的帮助。

Issue On SwiftMessage GitHubIssue On WhatsNewKit GitHub

SwiftMessage GitHub 上的问题 WhatsNewKit GitHub上的问题

When I click presentationContextit brings me to the struct within the SwiftMessagesFramework. Usually, when I've had the "has no member" warning I cannot click to see the original place where it exists.

当我单击presentationContext它时,它会将我带到SwiftMessages框架中的结构。通常,当我收到“没有成员”警告时,我无法单击查看它存在的原始位置。

I assume this has something to do with cocoa pods, but haven't been able to find a solution yet. What can I do to correct this issue? If anyone could help would be deeply appreciated been stuck on this for a day now.

我认为这与可可豆荚有关,但尚未找到解决方案。我能做些什么来纠正这个问题?如果有人可以提供帮助,将不胜感激,现在已经坚持了一天。

Update: The two frameworks latest builds were for swift 4.2. When I changed the version of each framework to one that was built in swift 4.0 I got the project to build.

更新:这两个框架的最新版本是针对 swift 4.2 的。当我将每个框架的版本更改为在 swift 4.0 中构建的版本时,我得到了要构建的项目。

回答by Karim Karimov

Make sure that, your project Swift Language Version is in the proper version. SwiftMessages 6.0.0 works with Swift 4.2. Xcode->Project->Target->Build Settings->Swift Language Version

确保您的项目 Swift 语言版本是正确的版本。SwiftMessages 6.0.0 适用于 Swift 4.2。 Xcode->Project->Target->Build Settings->Swift 语言版本

回答by Jeremy Vandermeersch

for pod SwiftMessages if your app is not swift 4.2 you need to user the version 5.01 pod 'SwiftMessages', '~> 5.0.1'

对于 pod SwiftMessages,如果您的应用不是 swift 4.2,您需要使用 5.01 版的 pod 'SwiftMessages', '~> 5.0.1'

and it will work like a charm

它会像魅力一样发挥作用

回答by yybot

Set Swift version to 4.2 then pod deintegrate, pod install, fix this problem for me. Thanks @alejandro-iván

将 Swift 版本设置为 4.2,然后 pod deintegrate,pod install,为我解决这个问题。谢谢@alejandro-iván

回答by Tommie C.

All of the answers were helpful to me. In my case, I only install frameworks manually but this kind of problem also happens. I tried all of the answers and was still getting this issue during the build. Curiously, while coding, I could cmd-click and resolve all of the "missing" components. I also cleaned and deleted derived data, restarted Xcode, etc.

所有的答案对我都有帮助。就我而言,我只手动安装框架,但也会发生这种问题。我尝试了所有答案,但在构建过程中仍然遇到此问题。奇怪的是,在编码时,我可以 cmd-click 并解决所有“丢失”的组件。我还清理和删除了派生数据,重新启动了 Xcode 等。

I eventually got it working by inducing these additional steps:

我最终通过引入这些额外的步骤让它工作:

On eachof the framework project/targets (including my own):

每个框架项目/目标(包括我自己的)上:

  • Verify consistent Swift version (4.2 in my case)
  • Set Build for Active Architecture Only to No
  • Set Valid Architecture to arm64, armv7(to match with base project)
  • Set Optimization Level to None(for Debug)
  • Set Compilation Mode to Whole
  • 验证一致的 Swift 版本(在我的情况下为 4.2)
  • 将仅针对活动架构的构建设置为
  • 将 Valid Architecture 设置为arm64、armv7(与基础项目匹配)
  • 将优化级别设置为(用于调试)
  • 将编译模式设置为整体

回答by Phantom59

I had several frameworks (homegrown) plus my app. Somehow they ended up being out of sync as far as the Swift version. Make sure that all frameworks are the same version. In my case, they all needed to be set to Swift 4.2. If you haven't done the migration to 4.2 then remember that Xcode helps with this: Edit -> Convert -> To Current Swift Syntax.

我有几个框架(本土)加上我的应用程序。不知何故,他们最终与 Swift 版本不同步。确保所有框架都是相同的版本。就我而言,它们都需要设置为 Swift 4.2。如果您还没有迁移到 4.2,请记住 Xcode 对此有帮助:Edit -> Convert -> To Current Swift Syntax。

回答by ram

Make sure that, Your project build settings Optimization Levelis in No Optimization[-Onone].

确保您的项目构建设置优化级别处于无优化 [-Onone]。

enter image description here

在此处输入图片说明

回答by Diego

I solved this way:

我是这样解决的:

  1. Comment all pods in your .podfile
  2. From your terminal, run the command pod install --no-repo-update
  3. Open Xcode perform a clean and rebuild the project
  4. Now open your .podfile and uncomment the first library
  5. From your terminal, run the command pod install
  1. 注释.pod文件中的所有 pod
  2. 从终端运行命令pod install --no-repo-update
  3. 打开Xcode执行清理并重建项目
  4. 现在打开您的.pod文件并取消注释第一个库
  5. 从终端运行命令pod install

Repeat steps 2 - 3 - 4 -5for each uncomment library in your .podfile

.pod文件中的每个取消注释库重复步骤2 - 3 - 4 -5

I hope it can be of your help.

我希望它能对你有所帮助。

回答by Fuhad saneen

Same issue happened to me in Xcode 10.2, it was a Xcode bug..! So, I opened in older Xcode version(9.4), and it worked fine. Then I updated to the Xcode 10.2.1 after it's release -> Clean and build your project, now my problem solved.

同样的问题在 Xcode 10.2 中发生在我身上,这是一个 Xcode 错误..!所以,我在旧的 Xcode 版本(9.4)中打开,它运行良好。然后我在发布后更新到 Xcode 10.2.1 -> Clean and build your project,现在我的问题解决了。

回答by Vincent Sit

I'm having the same problem, my Xcode version is 10.2.1 (10E1001), Cocoapods version is 1.7.0.beta.2.

我遇到了同样的问题,我的 Xcode 版本是 10.2.1 (10E1001),Cocoapods 版本是 1.7.0.beta.2。

I returned to Cocoapods 1.6.1 and the problem was solved. The specific steps are:

回到Cocoapods 1.6.1,问题解决了。具体步骤是:

  1. pod deintegrateto cancel the integration.
  2. Uninstall all Cocoapods.

    for i in $( gem list --local --no-version | grep cocoapods );
    do
        gem uninstall $i;
    done
    
  3. Install the stable version of Cocoapods. For now it's 1.6.1.

    gem install cocoapods
    
  4. Clean Project and empty DerivedData?

  5. pod install
  6. Recompile the project
  1. pod deintegrate取消积分。
  2. 卸载所有 Cocoapods。

    for i in $( gem list --local --no-version | grep cocoapods );
    do
        gem uninstall $i;
    done
    
  3. 安装稳定版的 Cocoapods。现在是 1.6.1。

    gem install cocoapods
    
  4. 清理项目并清空派生数据?

  5. pod install
  6. 重新编译项目

回答by Wilson Campusano

In my case it was a code error:

就我而言,这是一个代码错误:

self.myDto.map{ (dto)} in 
      var stringValue = (dto.value(forKey: "name") as! String)
      stringValue.append("c")
      return stringValue
}

Just removed that stringValuevariable fixed the problem.

刚刚删除该stringValue变量解决了问题。