Search code examples
iosxcodecocoapodsxcconfig

Using CocoaPods with multiple projects


I have a workspace that contains:

  • myiPhone.xcodeproj
  • sharedStuff/sharedStuff.xcodeproj

sharedStuff.xcodeproj builds a static library that is a dependency to myiPhone.xcodeproj (for simplicity assume that each project has a single target).

Now I want to add a library through CocoaPods that should be available to both projects.

My Podsfile looks like this:

workspace 'myWorkspace.xcworkspace'
platform :ios

target :myiPhone do
    xcodeproj 'myiPhone.xcodeproj'
    pod 'MBProgressHUD', '~> 0.6'
end


target :sharedStuff do
    xcodeproj 'sharedStuff/sharedStuff.xcodeproj'
    pod 'MBProgressHUD', '~> 0.6'
end

When I build I get these errors:

diff: /../Podfile.lock: No such file or directory diff: /Manifest.lock: No such file or directory error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.

Anyone have a clue what's going on here?

UPDATE: From the looks of it the PODS_ROOT variable is not set when the "Check Pods Manifest.lock" build phase is executed.


Solution

  • The first targets in your xcode projects have a build phase to perform a diff on two lock files. But it seems like your xcode projects configurations are not referencing the user defined settings configured in Pods/Pods-libPods.xcconfig.

    It looks like you are trying to link a Pod with specific targets in multiple xcodeprojs. If my assumption is correct, you are using the target attribute incorrectly. The target attribute creates a new static library within the Pods project that includes the Pods you configured within that target.

    The default target for the Pods xcodeproj is libPods which generates the libPods.a static library. This is generated if you do not specify a target. So if you don't care about generating multiple static libaries in the Pods xcodeproj, don't bother defining a target and use the link_with attribute to link the default libPods target (static library) to the targets in your xcodeprojs.

    For example, the following Podfile will create a libPods target in Pods.xcodeproj which will add MBProgressHUD sources to the compile phase then add the xcconfig file defining PODS_ROOT and the PODS_HEADER_SEARCH_PATH for example to each of your xcodeprojs. It will then link this static library to the targets you specified with link_with and xcodeproj

    workspace 'myWorkspace.xcworkspace'
    platform :ios
    
    xcodeproj 'myiPhone.xcodeproj'
    link_with 'myiPhone'
    xcodeproj 'sharedStuff/sharedStuff.xcodeproj'
    link_with 'sharedStuff'
    
    pod 'MBProgressHUD', '~> 0.6'