静态库依赖项的最佳实践 [英] Best practice for static library dependencies

查看:79
本文介绍了静态库依赖项的最佳实践的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个依赖于其他库的静态库(在我的例子中是SBJSON和ASIHTTPRequest)。

I'm writing a static library that has dependencies on other libraries (in my case SBJSON and ASIHTTPRequest).

如果我将这些外部依赖项编译到我的库中,那么我就无法链接到编译了这些类的其他库。我的目标是创建一组静态可以导入到任何新应用程序中的公司库,将这些依赖项编译到库中显然不是一种选择。

If I compile these external dependencies into my library then I can't link against other libraries that have these classes compiled in. As my goal is to create a set of static libraries for my company that can be imported into any new app, compiling these dependencies into the library is obviously not an option.

有没有人有任何建议/最佳实践来创建一组具有公共依赖关系的共享静态库?

Does anyone have any advice / best practices for creating a suite of shared static libraries with common dependencies?

推荐答案

您可以使用依赖管理器,如 CocoaPods VendorKit 拉在所需的库中,以及它所有的传递依赖 - 库所依赖的库。

You could use a dependency manager like CocoaPods or VendorKit to pull in the required library, as well as all it's transitive dependencies - libraries that the library depends on.

依赖管理器的工作是管理传递依赖中的任何冲突 - 例如,如果两个库都使用不同的版本SBJSON,它将解决该怎么做。您所要做的就是在配置文件中声明所需的顶级库,它将确定需要哪些子库并将它们引入您的Xcode项目。

It's the job of the dependency manager to manage any conflicts in transitive dependencies - eg if two libraries both use different versions of SBJSON, it will work out what to do. All you have to do is declare the top level library you want in a config file and it will work out what sub-libraries are needed and pull them into your Xcode Project.

CocoaPods有一个很好的方法来管理它,通过将所有库作为源提取,然后将它们全部编译到一个静态库中 - 在一个单独的项目中。然后通过工作区将其链接到您的项目中。

CocoaPods has a nice way of managing this by pulling in the all of the libraries as source, and then compiling them all into a single static library - in a separate project. This is then linked into your project via a workspace.

VendorKit采用类似的方法,但使用单个项目文件。

VendorKit takes a similar approach, but uses a single project file.

CocoaPods和VendorKit都允许您轻松地将库发布到中央存储库。如果您愿意,CocoaPods允许您维护自己的中央仓库的私有或公共分支 - 即作为企业存储库。

Both CocoaPods and VendorKit allow you to easily publish your library to a central repository. CocoaPods allows you to maintain your own private or public fork of the central repo, if you wish - ie as an enterprise repository.

大多数情况下,这会让你摆脱困境。在极少数情况下,您的库可能依赖于另一个公共库的非常特定的旧版本。在这种情况下,您可以使用工具重命名该库中的所有头/ impl文件以避免冲突。

Most of the time this will get you out of trouble. In rare cases your library might depend on a very specific, older version of another common library. In this case you could use a tool to rename all of the header/impl files in that library to avoid collisions.

:截至2013年1月,还有一个新的竞争者 - Maven Xcode插件。

: As of January, 2013 there is also a new contender - Maven Xcode plugin.

这篇关于静态库依赖项的最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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