Cocoapods with multiple projects and shared libraries

805 views Asked by At

I have a workspace with several projects. Each customer has its own project and each customer's project depends on

  1. Core project: Static library with common code
  2. Interface project: Static library with common interface, i.e. UIViewController code

The Interface library depends on Core too.

Project dependency

Each one of the projects have two targets. The normal target and the tests target, so,

  • Core, CoreTests
  • Interface, InterfaceTests
  • Customer, CustomerTests

Since every aspect of the app is being heavily developed at the moment, I have all projects on the same workspace and also on the same repository because changes may occur in any part of the structure at any moment.

I want to use CocoaPods to manage the dependencies that the projects have. To keep it simple let's say I can to use OCMock on every test target, NewRelicAgent on every normal target and Reachability only on the Core target.

The Podfile looks like this:

workspace 'CompanyWorkspace'
xcodeproj 'Core/Core.xcodeproj'
xcodeproj 'Interface/Interface.xcodeproj'
xcodeproj 'Customer/Customer.xcodeproj'

target :Core do
    platform :ios, '6.0'
    xcodeproj 'Core/Core.xcodeproj'
    pod 'NewRelicAgent', '~> 5.1'
    pod 'Reachability', '~> 3.2'
end

target :CoreTests do
    platform :ios, '6.0'
    xcodeproj 'Core/Core.xcodeproj'
    pod 'OCMock', '~> 3.1'
end


target :Interface do
    platform :ios, '6.0'
    xcodeproj 'Interface/Interface.xcodeproj'
    pod 'NewRelicAgent', '~> 5.1'
end

target :InterfaceTest do
    platform :ios, '6.0'
    xcodeproj 'Interface/Interface.xcodeproj'
    pod 'OCMock', '~> 3.1'
end


target :Customer do
    platform :ios, '7.0'
    xcodeproj 'Customer/Customer.xcodeproj'
    pod 'NewRelicAgent', '~> 5.1'
end

target :CustomerTests do
    platform :ios, '7.0'
    xcodeproj 'Customer/Customer.xcodeproj'
    pod 'OCMock', '~> 3.1'
end

I solved the dependencies between my structure by adding the static library Core.a into the build phases of Interface.a and by changing User Header Search Paths so it finds the headers. In the Customer project I added Core.a and Interface.a into the build phases and modified User Header Search Paths so it finds the code from Core and Interface.

The problem with this approach is that Core and Interface build an execute their tests properly but when I try to build Customer.app I get a number of duplicate symbols errors. I believe that this is because the target keyword in CocoaPods generates static libraries with the dependencies configured so when Customer is built it tries to include twice the code from Core. Any idea as how to solve this problem?

0

There are 0 answers