简体   繁体   English

iOS框架:在拥有其他第三方库时,如何更好地实现这一目标?

[英]iOS Frameworks: Ways to make this better, when having other third-party libraries?

Cross-posting from here, from the issue I created on the github project jverkoey/iOS-Framework . 从这里交叉发布,来自我在github项目jverkoey / iOS-Framework上创建的问题。 It seems to get you 90% of the way, in regards to making a nice .framework for iOS to distribute to third-parties. 在为iOS制作一个漂亮的.framework以分发给第三方时,它似乎可以让你获得90%的支持。

But what if you're distributing other third-party SDKs in your .framework? 但是,如果您在.framework中分发其他第三方SDK,该怎么办? Is there a way to include .a, .framework, and other .dylib files that these other third-party SDKs have, directly into your .framework? 有没有办法将这些其他第三方SDK所包含的.a,.framework和其他.dylib文件直接包含在您的.framework中?

Is it possible to have other third-party frameworks wrapped by the framework that you create, as outlined in this project that may have things like: 是否有可能让您创建的框架包含其他第三方框架,如此项目中概述的那样可能包含以下内容:

  • .a files .a文件
  • other .framework files 其他.framework文件
  • other .dylib files 其他.dylib文件

So that devs using your framework, wouldn't have to manually add .a, .framework, and .dylib files from the third-party libraries your framework wraps? 那么开发人员使用你的框架,不必手动添加你的框架包含的第三方库中的.a,.framework和.dylib文件?

I'd love to be schooled in why this is not possible, if so, for each of those files. 我很乐意接受教育,为什么这不可能,如果是这样,对于每个文件。


Resources: 资源:

(via https://github.com/jverkoey/iOS-Framework/issues/67 ) (通过https://github.com/jverkoey/iOS-Framework/issues/67

I would say it's not recommended to embed other frameworks/libraries. 我想说不建议嵌入其他框架/库。 It can cause issues and it bloats the framework. 它可能会导致问题,并使框架膨胀。 Look at what Apple does, when you need a library/framework you add it. 看看Apple的功能,当您需要添加它的库/框架时。

When you publish a framework, just state (website/readme/github) what it depends on (ie CoreLocation.framework, CoreGraphics.framework, etc). 当您发布框架时,只需说明它所依赖的内容(website / readme / github)(即CoreLocation.framework,CoreGraphics.framework等)。 If open source, you might need to state a specific version that your framework works with. 如果是开源,您可能需要声明框架使用的特定版本。

I've had tons of headaches from 3rd party libraries/frameworks that had an embedded source code dependency (Amazon caused my app to fail to build with their iOS AWS SDK and SBJSON inner dependency). 我从第三方库/框架中遇到了大量令人头疼的问题,这些库/框架具有嵌入式源代码依赖性(亚马逊导致我的应用无法使用其iOS AWS SDK和SBJSON内部依赖性构建)。

NOTE If you do include 3rd party source in your build, you need to make sure you rename all the code files (ie SourceFile.h > PSSourceFile.h, etc). 注意如果在构建中包含第三方源,则需要确保重命名所有代码文件(即SourceFile.h> PSSourceFile.h等)。 Otherwise people will not be able to integrate your .framework if they already have the source in their project. 否则,如果他们已经在项目中拥有源代码,那么人们将无法集成您的.framework。 They'll get duplicate symbols, and their only solution is to either: not use your framework or rename their files to prevent duplicate symbols (I had to manually rename a ton of files from the IOS AWS SDK before they fixed the issue). 他们将获得重复的符号,他们唯一的解决方案是:不使用您的框架或重命名他们的文件以防止重复的符号(我必须在修复问题之前手动重命名IOS AWS SDK中的大量文件)。

First off, iOS does not support the creation dynamical libraries. 首先,iOS不支持创建动态库。 The only dynamic libraries that can be used by iOS are those already included within code for iOS projects. iOS可以使用的唯一动态库是已包含在iOS项目代码中的动态库。 This is due to the nature of how iOS handles dynamic libraries and allows them to be shared across applications. 这是由于iOS处理动态库的方式的性质,并允许它们跨应用程序共享。 Since a library that you link should not be shared across applications, they restrict this. 由于您链接的库不应跨应用程序共享,因此它们会对此进行限制。

This leaves us with static libraries. 这给我们留下了静态库。 In iOS there are two ways to package a static library. 在iOS中,有两种方法可以打包静态库。 The first is by just creating the .a and setting the headers. 第一种方法是创建.a并设置标题。 The other is to create a .framework package that just organizes the static archive and the headers in a format that's easy to handle by the system. 另一种是创建一个.framework包,它只是以一种易于系统处理的格式组织静态存档和头文件。

With that in mind a static library is just a collection of compiled source objects .o files in a .a archive. 考虑到这一点,静态库只是.a存档中已编译源对象.o文件的集合。 These have not been linked and the symbols have not been created for them. 这些尚未链接,并且尚未为它们创建符号。 From my understanding this is why header location is important and in particular which headers are public, protected and private. 根据我的理解,这就是标头位置很重要的原因,特别是哪些标题是公共的,受保护的和私有的。

There are reasons that you might not want to bundle static libraries into another static library. 您可能不希望将静态库捆绑到另一个静态库中。 If you have two libraries that both contain a dependent static library then you will run into conflicts that can cause a lot of issues. 如果您有两个包含依赖静态库的库,那么您将遇到可能导致许多问题的冲突。 The third link you posted talks about this. 您发布的第三个链接谈到了这一点。

Now if you don't care about the problems that are going to arise by two libraries both including the same static library dependency, the way you would go about this is by combining the two libraries together. 现在,如果您不关心两个库(包括相同的静态库依赖项)将会出现的问题,那么您可以将两个库组合在一起。 I have not tested this but I believe you can do it multiple ways. 我没有测试过这个,但我相信你可以通过多种方式做到这一点。 I will modify this post after I test. 我测试后会修改这篇文章。 The tools would be: 工具将是:

libtool which in the end would just lipo the two together libtool最终会将两者结合在一起

lipo which combines two static libraries (mostly in the creation of architecture specific fat binaries) lipo结合了两个静态库(主要是创建特定于体系结构的胖二进制文件)

ar which you would use to e(x)tract the .o files from both .a archives and then archive them back together into one binary. AR,你会用E(X)从两个的.a归档道.o文件,然后将它们归档到一起成一个二进制文件。

You would need to include the headers for both archives in your header search paths for either of these methods to gain public access to them outside of your project and I'm not 100% on how your framework compiles with dependencies on these joined libraries but I am creating a test project to see. 您需要在标题搜索路径中包含这两个存档的标题,以便在项目之外获取对它们的公共访问权限,并且我不是100%关于框架如何编译依赖于这些连接的库但是我我正在创建一个测试项目。

Other than all of that, including the source of another library and building it into your library instead of its own separate library is one way to go about it too. 除了所有这些之外,包括另一个库的源代码并将其构建到您的库而不是它自己的独立库中也是一种方法。

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

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