iOS:Command CompileSwiftSources failed with a nonzero exit code问题解决

6,012 阅读2分钟

小知识,大挑战!本文正在参与“程序员必备小知识”创作活动。

前言

最近我在自己项目在Xcode13中运行Release模式,然后报了错,因为问题目前已经解决了,所以没截图了,不好意思,错误信息如下:

remark: Incremental compilation has been disabled: it is not compatible with whole module optimization

Command CompileSwiftSources failed with a nonzero exit code

这里记录一下我解决问题的过程。

先百度了一把

百度将问题的链接指向了某乎:

实际上苹果已经在 Release Note 里说过这事了:

Compilation might fail without displaying the errors responsible for the failure. For example, you might see the message “Command CompileSwiftSources failed with a nonzero exit code” without an accompanying failure reason. (43033749) Workaround: Disable batch mode by adding a user-defined build setting named SWIFT_ENABLE_BATCH_MODE and set it to NO.

而解决方案是在Build Settings中添加一个 User-Defined Setting字段为命名为 SWIFT_ENABLE_BATCH_MODE,设置为 NO。

image.png

根据文章说的,通过这样设置后,就可以真正的知道到底是哪里出错了。

但是,我这样设置之后,依旧报同样的错误,没有指明确切的问题。

大家都懂的,这种问题其实还是Google更专业

Google果然还是亲爹,问题一输入,搜索结果直接就到了Stack Overflow,其中有一个帖子引起了我的注意:

image.png

这个回答的意思是remark: Incremental compilation has been disabled: it is not compatible with whole module optimization并不是问题的关键,最关键的是跟在后面的那句问题。

也就是:

Command CompileSwiftSources failed with a nonzero exit code

于是我缩小问题的句子范围,继续Google。

在Stack Overflow中有不少的回答,比如通过pod命令更新第三库、清空Mac中的编译缓存等等。

都试过,但是还是依旧报同样的错误。

在Stack Overflow中找到了这么一个回答引起了我的注意:

image.png

我立马意识到的Kingfisher库引用了CommonCrypto的框架。

为啥,因为前几天的文章我还拿其中的手撕MD5举例子:Swift的中MD5加密算法

接着我先注释掉了Kingfisher,进行pod install操作,然后再放开Kingfisher的注释,进行pod install --repo-update,重新安装Kingfisher。

在Release模式下的编译就好了,App在手机上也正常运行起来。

参考文档

Xcode 10.2 编译失败,如何对敌?

remark: Incremental compilation has been disabled: it is not compatible with whole module optimization

Command CompileSwift failed with a nonzero exit code in Xcode 10 [duplicate]

Swift的中MD5加密算法

总结

这次的问题有些让我摸不着头脑,也只能亦步亦趋的通过网络搜索与尝试。

当然Google一般情况下都是会比较靠谱的,但是代价是需要架梯子。

说实话,作为程序员有的时候架梯子真的是在所难免,有的时候不架梯子,甚至连GitHub都上不去。

好了,今天就是记录一个调试问题的过程。

我们下期见。