Search code examples
iosobjective-cxcodedependency-managementxcode11

How to manage transitive dependency for local Xcode projects


I have two Objective C dynamic frameworks X and Y and another Objective C app Z. All these frameworks and apps have been created by me locally. Framework X is the very base framework used by framework Y and the app Z. So the dependency graph is something like the following:

  1. Y ---> X

  2. Z ---> X

  3. Z ---> Y (---> X)

I want all my targets to be debuggable and to pick the platform tools based on run destination (device/simulator). So I have added dependencies as sub-projects to the main projects and have linked them with the dependent projects to generate implicit dependencies by Xcode.

The set up 1 and 2 works great independently. But I am struggling with the set up 3 which is creating duplicate build rules for the target X due to transitive dependency on it (target Y and Z both depends on it) and subsequently failing the build process.

Anyone has any idea on how to deal with this situation? Thanks in advance!


Solution

  • Actually there is a way through which I could finally solve the issue of transitive dependency in Xcode. I have to use Workspace (.xcworkspace) rather than a Xcode project (.xcodeproj).

    To get it done use the following steps:

    1. Close all related and open Xcode projects.
    2. Create a new Workspace in the root directory from File > New > Workspace. Open the workspace by double clicking onto it and drag/drop the required projects to the workspace.
    3. Add the independent framework (X in my question) output to both of the dependent project targets (Y and Z) by adding it under the Framework and Libraries section. Embed the dynamic library only to the top level application (Z) and do not embed it to the intermediate dependent target library (Y).
    4. Add the intermediate framework (Y) to the root level app under Framework and Libraries section and embed it to the root app bundle.

    This setup works like a charm for me without ever creating duplicate build rules and it spontaneously picked up the dependency as well.

    Obviously, you can not do this if your independent framework is a static library and in that case it will be linked to both the dependent targets causing duplicate symbols issue during linking.