简体   繁体   English

如何管理本地 Xcode 项目的传递依赖

[英]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.我有两个 Objective C 动态框架 X 和 Y 以及另一个 Objective C app Z。所有这些框架和应用程序都是我在本地创建的。 Framework X is the very base framework used by framework Y and the app Z. So the dependency graph is something like the following:框架 X 是框架 Y 和应用程序 Z 使用的非常基础的框架。因此依赖关系图类似于以下内容:

  1. Y ---> X Y ---> X

  2. Z ---> X Z ---> X

  3. Z ---> Y (---> X) 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.因此,我将依赖项作为子项目添加到主项目中,并将它们与依赖项目链接,以通过 Xcode 生成隐式依赖项。

The set up 1 and 2 works great independently.设置 1 和 2 可以独立工作。 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.但是我正在为设置 3 苦苦挣扎,该设置 3 由于对目标 X 的传递依赖(目标 Y 和 Z 都依赖它)而为目标 X 创建重复的构建规则,随后构建过程失败。

Anyone has any idea on how to deal with this situation?任何人都知道如何处理这种情况? Thanks in advance!提前致谢!

It seem that in Objective-C, We can't link a dynamic framework to another dynamic framework, or to a command line tool.似乎在 Objective-C 中,我们无法将动态框架链接到另一个动态框架或命令行工具。 It's always raise an exception, when running in production在生产中运行时总是会引发异常

Dyld Error Message:
  Library not loaded: @rpath/XFrameworks.framework/Versions/A/XFrameworks

For your situation, What I think might solve your problem对于您的情况,我认为可能会解决您的问题

  • X (Core features) can be built in static library X (核心功能)可以内置在 static 库中
  • Y can be built in type of dynamic framework Y 可内置于动态框架类型
    • will link with X library将与 X 库链接
    • or link with others (I mean some another code base)或与其他人链接(我的意思是另一个代码库)
  • Z (your application) will link with Y framework Z (您的应用程序)将与 Y 框架链接

Actually there is a way through which I could finally solve the issue of transitive dependency in Xcode.实际上有一种方法可以最终解决 Xcode 中的传递依赖问题。 I have to use Workspace (.xcworkspace) rather than a Xcode project (.xcodeproj).我必须使用工作区 (.xcworkspace) 而不是 Xcode 项目 (.xcodeproj)。

To get it done use the following steps:要完成它,请使用以下步骤:

  1. Close all related and open Xcode projects.关闭所有相关并打开 Xcode 项目。
  2. Create a new Workspace in the root directory from File > New > Workspace.从 File > New > Workspace 在根目录中创建一个新的 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.通过在框架和库部分下添加独立框架(我的问题中的 X)output 到两个依赖项目目标(Y 和 Z)。 Embed the dynamic library only to the top level application (Z) and do not embed it to the intermediate dependent target library (Y).仅将动态库嵌入到顶级应用程序 (Z),不要将其嵌入到中间依赖目标库 (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.将中间框架 (Y) 添加到框架和库部分下的根级应用程序中,并将其嵌入到根应用程序包中。

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.显然,如果您的独立框架是 static 库,则您不能这样做,在这种情况下,它将链接到两个依赖目标,导致链接期间出现重复符号问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM