带有子项目和项目依赖项的 Xcode 工作区触发构建

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

Xcode workspaces with sub-projects and project dependencies triggering builds

xcodecocoaframeworksxcode5

提问by Jay

I wish there was better documentation for this for Xcode 5 but I couldn't find anything decent describing best practices for working with workspaces, so..

我希望 Xcode 5 有更好的文档,但我找不到任何像样的描述使用工作区的最佳实践,所以..

In a workspace with several projects (couple frameworks, 1 app) is it possible to have Xcode build all dependent projects onlywhen required (i.e. changes found) w/o having to include all projects in all dependent projects?

在具有多个项目(几个框架,1 个应用程序)的工作区中,是否可以让 Xcode在需要(即发现更改)时才构建所有相关项目,而不必将所有项目包含在所有相关项目中

I'd rather like to just have the frameworks in the project depending on it instead of having 5-6 sub projects in it as this is just a mess in the Navigation View-
files inside sub-projects show up in search results all the time, sub-projects in the NavView expand for whatever reason within projects..

我宁愿只在项目中拥有依赖于它的框架,而不是在其中包含 5-6 个子项目,因为这只是导航视图中的一团糟-
子项目中的文件一直显示在搜索结果中, NavView 中的子项目会因项目中的任何原因而扩展..

However, w/o including projects a particular project depends on I couldn't find a way to have Xcode 5 re-build the frameworks automaticallyif one of the dependencies has changed.

但是,如果不包含特定项目所依赖的项目,如果其中一个依赖项发生变化,我找不到让 Xcode 5 自动重新构建框架的方法

回答by Tomte

This solution was intended for another problem, but maybe it fills your needs.

此解决方案旨在解决另一个问题,但也许它可以满足您的需求。

After adding your subproject to the workspace:

将子项目添加到工作区后:

  1. Select the Target which should use the newly added subproject
  2. In "Link Binaries with Libraries" under Build Phases hit the + button
  3. If the Library does′t show up hit "Add Other..."
  4. Navigate to the Folder where the project file (*.xcodeproj) lies
  5. Mark it and hit "Open"
  6. Now you should see the Project File show up under "Link Binaries with Libraries"
  7. Under "Target Dependencies" in the same tab, hit the + button
  8. Now you should see the necessary files
  9. Check yours and hit "Add"
  10. Again in the "Link Binaries with Libraries" hit the + button
  11. Now your .a file should show up and you can choose and add it
  1. 选择应该使用新添加的子项目的目标
  2. 在 Build Phases 下的“Link Binaries with Libraries”中,点击 + 按钮
  3. 如果图书馆没有出现,请点击“添加其他...”
  4. 导航到项目文件 (*.xcodeproj) 所在的文件夹
  5. 标记它并点击“打开”
  6. 现在您应该看到项目文件显示在“Link Binaries with Libraries”下
  7. 在同一选项卡中的“目标依赖项”下,点击 + 按钮
  8. 现在你应该看到必要的文件
  9. 检查你的并点击“添加”
  10. 再次在“Link Binaries with Libraries”中点击 + 按钮
  11. 现在您的 .a 文件应该显示出来,您可以选择并添加它

Now you are using the chosen library for your target. Repeat those steps for every target which needs this subproject. Hope that helps! For me it did because i could not manage to add dependencies to it before...

现在您正在为您的目标使用所选的库。对需要此子项目的每个目标重复这些步骤。希望有帮助!对我来说这样做是因为我之前无法向它添加依赖项...

Greetz, Tomte

格雷茨,托姆特

回答by JP Illanes

Just in case somebody else is having problems with this in Xcode 7: Make sure the project you want to add as subproject it's notopen, before you add it or drop it.

以防万一其他人在 Xcode 7 中遇到此问题:在添加或删除它之前,请确保要添加为子项目的项目打开。

回答by loretoparisi

On XCode 5You have to go

XCode 5你必须去

  • Select the project on the left tab
  • Choose the target in the TARGETS section
  • Then in Build Phases > Target Dependencies presse "+"
  • Choose the added project as target it will appear in the Target Dependencies list
  • 在左侧选项卡上选择项目
  • 在 TARGETS 部分选择目标
  • 然后在 Build Phases > Target Dependencies 按“+”
  • 选择添加的项目作为目标,它将出现在目标依赖项列表中

If it works, when building all target dependencies will be build together if needed.

如果它有效,在构建所有目标依赖项时,如果需要,将一起构建。

回答by Fostah

This is derived from Tomte's answer. His approach was causing me a Dependency Analysis Error. This is a more straight forward approach and explains why Tomte's answer works:

这是来自Tomte的回答。他的方法导致我出现Dependency Analysis Error。这是一种更直接的方法,并解释了为什么 Tomte 的答案有效:

  1. Click on the sub-project and drag it into the project that needs to target the sub-project.
  2. The options alert should now be displayed. Make sure Copy items if neededis not selected. Make sure Create groupsis selected. Make sure none of the project's targets are selected. Press the Finishbutton.
  3. Click on the project that you just added the sub-project reference to.
  4. Click on the target that you want to have a dependency on the sub-project.
  5. Click the Target Dependecies+ button.
  6. Notice the sub-project's product is listed as an option. Select it.
  1. 点击子项目,将其拖入需要针对子项目的项目中。
  2. 现在应该显示选项警报。确保未选择需要时复制项目。确保选择了创建组。确保没有选择任何项目的目标。按完成按钮。
  3. 单击您刚刚添加了子项目引用的项目。
  4. 单击要依赖于子项目的目标。
  5. 单击目标依赖项+ 按钮。
  6. 请注意,子项目的产品被列为一个选项。选择它。

Note that when using Tomte's approach, when the project is added to Link Binary With Libraries, a project reference is created. This project reference can be found in the Frameworks group of the project.

请注意,在使用 Tomte 的方法时,将项目添加到Link Binary With Libraries 时,将创建项目引用。该项目参考可以在项目的框架组中找到。

I'm conflicted as to whether this is a good approach or not. The scheme approach is not much better, in my opinion. I'm actually wondering why workspace project's don't have this relationship by default.

我对这是否是一个好方法感到矛盾。在我看来,方案方法也好不到哪里去。我实际上想知道为什么工作区项目默认没有这种关系。

At the very least, this should clear up the magic in Tomte's solution.

至少,这应该清除 Tomte 解决方案中的魔力。

回答by ulle

You could create a scheme that builds all targets.

您可以创建一个构建所有目标的方案。

回答by Rivera

Consider migrating to CocoaPods.

考虑迁移到CocoaPods

Not only it will fix your build problems, but with a project as complex as you describe it will ease your life when updating/adding/removing frameworks, changing target system version and resolving dependencies and conflicts.

它不仅可以解决您的构建问题,而且对于像您描述的那样复杂的项目,它可以让您在更新/添加/删除框架、更改目标系统版本以及解决依赖项和冲突时轻松生活。

Also your workspace will likely become only two projects.

此外,您的工作区可能只会变成两个项目。