Xcode workspaces with sub-projects and project dep

2019-03-09 07:12发布

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..

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

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..

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

6条回答
Luminary・发光体
2楼-- · 2019-03-09 07:37

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:

  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 needed is not selected. Make sure Create groups is selected. Make sure none of the project's targets are selected. Press the Finish button.
  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.

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.

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.

查看更多
叼着烟拽天下
3楼-- · 2019-03-09 07:43

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

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

查看更多
神经病院院长
4楼-- · 2019-03-09 07:50

Consider migrating to 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.

查看更多
Anthone
5楼-- · 2019-03-09 07:57

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 not open, before you add it or drop it.

查看更多
SAY GOODBYE
6楼-- · 2019-03-09 07:57

You could create a scheme that builds all targets.

查看更多
啃猪蹄的小仙女
7楼-- · 2019-03-09 07:59

On XCode 5 You have to go

  • 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

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

查看更多
登录 后发表回答