iOS:Command CompileSwiftSources failed with a nonzero exit code问题解决
前言
最近我在自己项目在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。
根据文章说的,通过这样设置后,就可以真正的知道到底是哪里出错了。
但是,我这样设置之后,依旧报同样的错误,没有指明确切的问题。
大家都懂的,这种问题其实还是Google更专业
Google果然还是亲爹,问题一输入,搜索结果直接就到了Stack Overflow,其中有一个帖子引起了我的注意:
这个回答的意思是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中找到了这么一个回答引起了我的注意:
我立马意识到的Kingfisher库引用了CommonCrypto的框架。
为啥,因为前几天的文章我还拿其中的手撕MD5举例子:Swift的中MD5加密算法。
接着我先注释掉了Kingfisher,进行pod install
操作,然后再放开Kingfisher的注释,进行pod install --repo-update
,重新安装Kingfisher。
在Release模式下的编译就好了,App在手机上也正常运行起来。
作者:season_zhu
链接:https://juejin.cn/post/7021327327325847560