Configuring Cocoapods with an existing static library and iOS application Configuring Cocoapods with an existing static library and iOS application ios ios

Configuring Cocoapods with an existing static library and iOS application


CocoaPods creates an implicit root target which by default links with the first target of the project. As you are creating another target and the link_with option is not inherited by children target definitions your set up is not working. In order to make the link_with option you can move it inside the block of the MyApp target definition.

As the Common target links with the Pods, if you link those with the MyApp it will result in the duplicate symbols error as the app links with Common. In this case you just need to make the headers available to the MyApp target. This is simple to do but there isn't a proper DSL yet so for the moment is a bit hacky as a solution (but supported).

workspace 'MyApp.xcworkspace'platform :ios, '5.0'target 'Common' do  pod 'AFNetworking',               '1.1.0'  pod 'TTTAttributedLabel',         '1.6.0'  pod 'JSONKit',                    '1.5pre'  pod 'Reachability',               '3.1.0'  target 'MyApp', :exclusive => true do    xcodeproj 'MyApp.xcodeproj'  endend


The solution I've adopted for this situation is as follows:

I set up the Podfile quite simply:

workspace 'MyApp.xcworkspace'platform :ios, '5.0'xcodeproj 'Common.xcodeproj'pod 'AFNetworking',               '1.1.0'pod 'TTTAttributedLabel',         '1.6.0'pod 'JSONKit',                    '1.5pre'pod 'Reachability',               '3.1.0'target 'MyApp' do    xcodeproj 'MyApp.xcodeproj'    # specific dependenciesend

This way the Common lib and MyApp are set up correctly to use all the dependencies. However, this will still cause duplicate symbols. The way to get around that is to simply delete libPods.a from the Common project's Build Phase. This is fine because we don't really want to link to the Cocoapods static lib to our static lib anyway. All the correct dependencies will be linked when you build the app, and all the correct header paths are set up in the .xccconfig files so Xcode/AppCode will still provide all your auto-completions and everything will compile.

You'll need to delete the libPods.a each time you run pod install which is a bit of a pain, but it might be better suffering that than managing all the dependencies manually.

Update: I'm working on this as I write and I've just noticed it's important not to use the Linker Flags Cocoapods sets up within your static library. By default, my static lib had overridden their value with no value but Cocoapods warns against this and advises you use $(inherited). Just ignore it.


matomo