使用嵌入在动态框架中的第三方框架 [英] Use third party framework which is embedded in dynamic framework

查看:135
本文介绍了使用嵌入在动态框架中的第三方框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,ios动态框架和静态的重大变化是静态链接时(在启动之前)静态链接到代码,动态在启动/运行时链接

As i understand the big change from ios dynamic framework and static is that static is linked statically to the code at link time (prior to launch) and dynamic is linked at launch/runtime

现在我有一个测试项目:

Now i have a test project:

我的项目有一个动态框架链接到它 - A.framework。

My project have a dynamic framework linked to it - A.framework.

import A.framework

A.framework里面嵌入了一个框架--B .framework

A.framework have a framework embedded inside of it - B.framework

在我的主项目中,我想使用来自B.framework的课程

In my main project i want to use classes from B.framework

现在我看到了主项目中的简单导入语句:

Now i see that with a simple import statement in the main project:

import B.framework

它实际上可以工作,我可以使用嵌入在链接的A.framework中的B.framework内部的代码

It actually work and i can use code from inside of the B.framework which is embedded in linked A.framework

怎么样?它是安全可靠的吗?主项目如何识别B.framework?

How can it be? is it something that is safe and reliable to use? How does the main project recognize the B.framework?

主项目如何直接将B.framework链接到项目?在这种情况下,我在链接时看到许多重复符号错误

What about cases where the main project directly link the B.framework to the project? in this case i see many "duplicate symbol errors" at link time

最重要的是我如何构建A.framework而不在其中嵌入B.framework ,当然偏离使用其类和函数

任何澄清都会有所帮助:)

Any clarifications will help :)

推荐答案

正如您所注意到的,链接B.framework会导致重复的符号。这就是A.framework不应该嵌入B.framework的原因。如果任何机会让消费应用程序关心嵌入式框架,那么你绝不能在另一个框架中嵌入框架(实际上,这意味着你真的应该永远不会这样做。)

As you note, linking B.framework would lead to duplicate symbols. This is why A.framework should not embed B.framework. You must never embed a framework in another framework if there is any chance that the consuming application will care about the embedded framework (in practice, this means you really should just never do it).

A.framework打包不正确。如果打包它,则应删除嵌入式框架并链接应用程序层的所有内容。如果其他人打包它,您应该打开它们的问题来纠正此错误。这个问题对动态框架来说并不陌生。这同样是静态框架的一个问题。链接依赖项的唯一合适时间是在应用程序层。

A.framework was incorrectly packaged. If you packaged it, you should remove the embedded framework and link everything at the application layer. If someone else packaged it, you should open an issue with them to correct this error. This issue is not new to dynamic frameworks. It was equally a problem with static frameworks. The only appropriate time to link dependencies is at the application layer.

(如果您控制整个生态系统(例如Apple)则会有例外。然后像伞形框架是可以接受的。但你不是Apple。)

(There is an exception if you control the entire ecosystem (e.g. Apple). Then things like umbrella frameworks are acceptable. But you're not Apple.)

编辑:可以将共享框架链接到另一个共享框架,但不能将其嵌入。关键是共享框架的唯一副本需要来自顶级应用程序。由于最后的链接步骤将在加载时发生,因此您将不会有重复的符号,因为共享框架只有一个副本。只是不要将子框架嵌入你的。

It is ok to link, but not embed, a shared framework into another shared framework. The key is that the only copy of the shared framework needs to come from the top-level application. Since that final link step will happen at load, then you won't have duplicate symbols because there is only one copy of the shared framework. Just don't embed the sub-framework into yours.

例如:


  • 使用框架目标创建项目

  • 将GMA.framework拖到框架目标(这将导致它链接但不嵌入)

  • 创建应用程序目标

  • 让应用程序链接GMA.framework和您的测试框架。这样可以正常工作而不会发生冲突,因为只有一个GMA.framework,它只嵌入在应用程序中。

  • Create project with framework target
  • Drag in GMA.framework to framework target (this will cause it to link but not embed)
  • Create App target
  • Have app link both GMA.framework and your test framework. This will work fine without collisions because there is only one GMA.framework, and it's only embedded in the app.

这篇关于使用嵌入在动态框架中的第三方框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆