ios Xcode 8 每次都重新编译完整的代码

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

Xcode 8 recompiling complete code every time

iosxcode

提问by Mahvish

With any change in code (though file is not in .pch), complete project recompiles every time.

随着代码的任何更改(尽管文件不在 .pch 中),每次都会重新编译完整的项目。

回答by Nhat Dinh

Update 2017/1/2

更新 2017/1/2

This issue has not been resolved at Xcode 8.2.1 (for my project)

此问题尚未在 Xcode 8.2.1 中解决(对于我的项目)

How to survive?

如何生存?

Code IDE: Xcode/Atom
Build: xcrun
Debug: Xcode (Control + Command + R)

Update 2016/12/17

更新 2016/12/17

This issue has not been resolved at Xcode 8.2.

此问题尚未在 Xcode 8.2 中解决。

Update 2016/12/12

更新 2016/12/12

Atom to code and command line to build and debug is my choice now. Hope Apple will fix this legit bug soon.

Atom 代码和命令行来构建和调试是我现在的选择。希望苹果尽快修复这个合法的错误。

Update 2016/12/04

更新 2016/12/04

This issue seem resolved with Xcode 8.2 (beta 2).

Xcode 8.2 (beta 2)似乎已解决此问题。

But for me its not be resolved, i face this issue even when i use Xcode 8.2. You can give it a try (download Xcode8.2 beta2 here)

但对我来说它没有得到解决,即使我使用 Xcode 8.2 我也面临这个问题。您可以尝试一下(在此处下载 Xcode8.2 beta2 )

Build System ? Xcode will not rebuild an entire target when only small changes have occurred. (28892475)

构建系统 ? 当只发生小的更改时,Xcode 不会重建整个目标。(28892475)



Old answer:This is a work around:

旧答案:这是一种解决方法:

enter image description here"Build Setting" tab -> "C Language Dialect" -> Change it to "Compiler Default".

在此处输入图片说明“构建设置”选项卡 -> “C 语言方言” -> 将其更改为“编译器默认值”。

For reference:

供参考

The "C Language Dialect" was set to "GNU99" instead of "Compiler Default". Previously the standard was GNU99 but now its not. At some point Xcode did not migrate the library project settings correctly and so it was set to GNU99. Once I changed it to GNU99 it stopped recompiling all my code every time !

“C 语言方言”被设置为“GNU99”而不是“编译器默认值”。以前的标准是 GNU99,但现在不是。在某些时候,Xcode 没有正确迁移库项目设置,因此它被设置为 GNU99。一旦我将其更改为 GNU99,它每次都停止重新编译我的所有代码!

回答by Madhuri Mane

Go to Product -> Scheme -> Edit Scheme. Select Build in left side column and uncheck "Find implicit dependencies"

转到产品 -> 方案 -> 编辑方案。选择左侧栏中的构建并取消选中“查找隐式依赖项

But this flag should remain checked when you are building the project for first time..

但是当你第一次构建项目时,这个标志应该保持选中状态。

回答by Emilio Concepcion

Fix for me was just closing storyboard, I had the source file opened with the assisted editor and the storyboard file opened as well (closing the storyboard --- since I wasn't making any changes to it) removed all the unnecessary compiling

对我来说修复只是关闭情节提要,我用辅助编辑器打开了源文件,同时打开了情节提要文件(关闭情节提要 --- 因为我没有对其进行任何更改)删除了所有不必要的编译

回答by anders

UPDATED

更新

The single biggest improvement I was able to make was modularizing my project. Specifically modularizing the ORM layer which is used in almost every other class. By moving that code into a separate target within my project and importing it as a module I was able to greatly improve compilation times. No longer does Xcode decide to recompile unnecessary files when I do a build.

我能够做出的最大改进是模块化我的项目。专门模块化几乎所有其他类中使用的 ORM 层。通过将该代码移动到我项目中的一个单独目标并将其作为模块导入,我能够极大地缩短编译时间。当我进行构建时,Xcode 不再决定重新编译不必要的文件。

Now I use the Single Filecompilation method for fast incremental debug builds.

现在我使用单文件编译方法进行快速增量调试构建。

There are some other good suggestions in this link including code refactoring, https://medium.com/rocket-fuel/optimizing-build-times-in-swift-4-dc493b1cc5f5

此链接中还有一些其他很好的建议,包括代码重构, https://medium.com/rocket-fuel/optimizing-build-times-in-swift-4-dc493b1cc5f5

OLD

老的

Still has been a constant issue for me with Xcode 9. Like many of you I'm working on a large swift 4/cocoapodsproject with many source files and re-compiling every file every time is infuriating.

使用 Xcode 9 对我来说仍然是一个持续的问题。像你们中的许多人一样,我正在处理一个包含许多源文件的大型swift 4/cocoapods项目,每次重新编译每个文件都令人恼火。

So far I'm getting the best results with the following settings. I suggest you give it a try and see how it works for you.

到目前为止,我通过以下设置获得了最佳结果。我建议你试一试,看看它是如何为你工作的。

  • Schema -> Build -> "Find Implicit Dependencies" = TRUE
  • Build Settings -> Link-Time Optimization = Incremental
  • Build Settings -> Optimization Level (Debug) = None [-OO]
  • Build Settings -> Optimization Level (Release) = Fastest, Smallest [-Os]
  • Build Settings -> Increase Sharing of Precompiled Headers = YES
  • Build Settings -> Enable Incremental Distill = YES
  • 架构 -> 构建 -> “查找隐式依赖关系” = TRUE
  • 构建设置 ->链接时间优化 = 增量
  • 构建设置 ->优化级别(调试)= 无 [-OO]
  • 构建设置 ->优化级别(发布)= 最快、最小 [-Os]
  • 构建设置 ->增加预编译头文件的共享 = YES
  • Build Settings -> Enable Incremental Distill = YES

Added custom User-Defined build settings,

添加了自定义用户定义的构建设置,

  • Build Settings -> HEADERMAP_USERS_VFS = YES
  • 构建设置 -> HEADERMAP_USERS_VFS = YES

Note: I do not have the custom user-defined setting for whole module optimization.

注意:我没有用于整个模块优化的自定义用户定义设置。

回答by ua24

Check out all of your code on @IBDesignabledirectives in my particular case Xcode build project all of the time because I had some views on my storyboard that was contain this @IBDesignableattributes in it. Second thing is that I also have my storyboard opened in separate window (not tab) that is push my Xcode make builds for all of simulators forever.

@IBDesignable在我的特定情况下,始终查看有关指令的所有代码 Xcode 构建项目,因为我的故事板上有一些包含此@IBDesignable属性的视图。第二件事是,我还在单独的窗口(不是选项卡)中打开了我的故事板,这将永远推动我的 Xcode 为所有模拟器构建版本。

回答by Christopher Rogers

I changed a few things with my code regarding the prefix header that seem to have fixed this problem. I don't know which one actually did the trick, but I'll share them all in hopes that it helps someone else out there. If you don't have a prefix header set, then I guess this isn't the problem (or the problem is multifaceted).

我用我的代码更改了一些关于前缀标头的内容,这些内容似乎已经解决了这个问题。我不知道哪一个真正做到了这一点,但我会分享它们,希望它可以帮助其他人。如果您没有设置前缀标题,那么我想这不是问题(或者问题是多方面的)。

  1. Remove any imports from the prefix header that are files from the built products directory so you can change the build setting for this ("Precompiled Header Uses Files From Build Directory") to "No". Be sure it is not indirectly imported through other imports as well.
  2. Remove any imports from the prefix header that use Clang modules (libraries or frameworks that have a module.modulemap file in their Headers directory, so you can write code like @import MyModule). (For me, this and step 1 were one and the same.)
  3. Set the build setting for prefix header sharing to "Yes". (I don't think this is necessary, and it shouldn't have any effect in my own project. I'm just stating this because I changed it because I was willing to try anything. :))
  4. Exit Xcode and delete your DerivedData/ModuleCache directory (configured to be at ~/Library/Developer if I remember correctly).
  1. 从构建产品目录中的文件的前缀头中删除任何导入,以便您可以将此构建设置(“预编译头使用构建目录中的文件”)更改为“否”。确保它也不是通过其他进口间接进口的。
  2. 从使用 Clang 模块(在其 Headers 目录中具有 module.modulemap 文件的库或框架,因此您可以编写类似 的代码@import MyModule)的前缀标头中删除任何导入。(对我来说,这和第 1 步是一回事。)
  3. 将前缀标头共享的构建设置设置为“是”。(我不认为这是必要的,它不应该对我自己的项目产生任何影响。我之所以这么说是因为我改变了它,因为我愿意尝试任何事情。:))
  4. 退出 Xcode 并删除您的 DerivedData/ModuleCache 目录(如果我没记错,配置为 ~/Library/Developer)。

If that still doesn't work, you can try removing some more imports from your prefix header. There may be something tripping it up...

如果这仍然不起作用,您可以尝试从前缀标头中删除更多导入。可能有什么东西绊倒了它......

回答by Josh

Looks like they are actively working on it according to https://forums.developer.apple.com/thread/62737but a workaround is to add

看起来他们正在根据https://forums.developer.apple.com/thread/62737积极致力于它,但解决方法是添加

HEADERMAP_USES_VFS = YES

HEADERMAP_USES_VFS = YES

under the build settings of your target (Project -> Target -> Build Settings -> User Defined).

在目标的构建设置下(项目 -> 目标 -> 构建设置 -> 用户定义)。

This solution worked every time for me today, after no other solution working consistently for the past month.

在过去一个月没有其他解决方案始终如一地工作之后,这个解决方案今天每次都对我有用。

EDIT: Still sometimes recompiling everything, although it seems to do it much less frequently with this setting defined.

编辑:有时仍会重新编译所有内容,尽管在定义此设置的情况下似乎不那么频繁地执行此操作。

回答by Johnny

Apple released new beta version of Xcode yesterday (Nov 14)

Apple 昨天(11 月 14 日)发布了新的 Xcode 测试版

Xcode 8.2 beta 2

Xcode 8.2 beta 2

And this issue has been marked as resolved in the release note.

此问题已在发行说明中标记为已解决。

Build System

? Xcode will not rebuild an entire target when only small changes have occurred. (28892475)

构建系统

? 当只发生小的更改时,Xcode 不会重建整个目标。(28892475)

It is working for me. The build speed came back as usual. Everybody who is facing this issue, should give it a try!

它对我有用。构建速度照常恢复。每个遇到这个问题的人都应该尝试一下!

https://developer.apple.com/download/

https://developer.apple.com/download/

回答by ldiqual

Go to your target's build settings and set Defines Moduleto Yes.

转到目标的构建设置并设置Defines ModuleYes.

Worked for me for a couple builds, too soon to claim this is a definitive workaround, but at least we're trying.

为我工作了几个版本,现在说这是一个明确的解决方法还为时过早,但至少我们正在尝试。

回答by pflous

Madhuri Mane is totally right regarding this. To add a little more clarity, some important points to note:

Madhuri Mane 在这方面是完全正确的。为了更清楚一点,需要注意一些要点:

This is ONLY applicable if you have implicit dependancies on libraries/frameworks that your target relies on.

这仅适用于您对目标所依赖的库/框架有隐式依赖关系的情况。

If "Find Implicit Dependencies" is disabled :

如果禁用“查找隐式依赖项”:

Result: The library will not get built prior to building the application target. The application target fail to build.

Fix: To ensure that the second scenario does not happen, you must add the necessary targets into the targets list and order them correctly.

结果:在构建应用程序目标之前不会构建库。应用程序目标无法构建。

修复:为确保不会发生第二种情况,您必须将必要的目标添加到目标列表中并正确排序。

Source and further reading on the topic : https://pewpewthespells.com/blog/managing_xcode.html#scheme-action

关于该主题的来源和进一步阅读:https: //pewpewthespells.com/blog/managing_xcode.html#scheme-action

Now if your entire project is housed within one target and that takes 4 min to compile there isn't much you can do about this except break it up into frameworks to take advantage of the above or figure out where the compilation lags. If you are using something like PaintCode or have large chunks of UIKit code in swift change it to Objective-c it compiles far faster

现在,如果您的整个项目都位于一个目标内并且编译需要 4 分钟,那么除了将其分解为框架以利用上述内容或找出编译滞后的地方之外,您无能为力。如果你正在使用像 PaintCode 这样的东西或者有大量的 UIKit 代码快速将其更改为 Objective-c,它的编译速度会快得多