iOS dependency management and packaging

I'm completely new to iOS development and coming from an Android background. I was starting to look at what alternatives are out there for dependency management in iOS and found out that CocoaPods seems to be the most prevalent option.

After reading a lot of links about this topic I'm kinda at a loss and wondering what is the usual way dependencies are handled in iOS.

I have two questions:

1) What would the equivalent of using gradle to generate library (.aar) projects be in iOS? If there's any equivalent option. From what I've seen one can wrap static libraries and headers into frameworks and these can be used in other apps, is this the standard way to do it?

2) If (1) is correct, does CocoaPods offer a mechanism to add frameworks as dependencies?


I don't have a Android background but from what I understand of .aar files CocoaPods does something very similar. CocoaPods uses .podspec files (described here) to generate static libraries (and soon dynamic frameworks which are new in iOS 8) that are then linked into your project.

A podspec can define source files, assets, libraries, or frameworks that a source vendors for linking into your application. So yes it does support adding frameworks as dependencies, although until iOS 8 frameworks were not supported at all on iOS.

As far as the 'standard' way to do it, I think that's based on opinion. There are a few general ways to include dependencies you can choose from.

  • Drag files, frameworks, and whatever else you need into your project manually. Updating these is more difficult and that also means you have to configure your .xcodeproj depending on what features that library needs (such as ARC)

  • Drag a provided .xcodeproj into your project, and link the relevant target from the given project. This can be nice if the library provides a project that can build a framework or static library, in this case you'd pull in that library but their project would handle custom compiler flags.

  • Do either of the above while including them as git submodules. Assuming nothing massive changes in the project this helps a lot with updating your dependencies.

  • Use CocoaPods. CocoaPods will handle all the custom linking and updates based on semantic versioning (usually).

  • Use Carthage. Carthage is an in- between CocoaPods and the .xcodeproj solution. It will download code based on semantic versions defined by git tags, then you drag the generated frameworks into your project.

  • All of these options have pros and cons and the decision normally comes down to how you feel about the control you have over the inclusion of the library, and how automated you want it to be.


    I do not have android nor iOS background however I've been developing a CI tool for both platforms and here are the answers

  • As You mentioned this a framework and pods (libraries) from cocoapods are distributed that way. For instance, have a look at Apphance. When spec is clicked it's visible that this library will be accessible as a Apphance-Production.framework.

  • You add pods to Podfile and download them with pod install command. This command will made classes from Apphance accessible from the code. Some people do commit downloaded pods, other not (it's like adding jars or aars to source control).

  • 链接地址: http://www.djcxy.com/p/48302.html

    上一篇: 在Xcode中添加项目作为依赖项

    下一篇: iOS依赖管理和打包