29

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.

Mihai Damian
  • 11,193
  • 11
  • 59
  • 81

5 Answers5

25

I have 2 projects in my Workspace and the accepted answer didn't work for me. But finally I've managed how to get Cocoapods working properly with 2 projects. Here is how my pod file looks like:

workspace 'Projects.xcworkspace'
platform :ios, '8.0'

use_frameworks!

# ignore all warnings from all pods
inhibit_all_warnings!

def shared_pods
    # all the pods go here
    # pod 'Parse' etc.
end

xcodeproj 'Project1.xcodeproj'
xcodeproj 'Project2/Project2.xcodeproj'

target :Project1 do
  xcodeproj 'Project1'
  shared_pods
end

target :Project2 do
  xcodeproj 'Project2/Project2.xcodeproj'
  shared_pods
end
Andrey Gordeev
  • 30,606
  • 13
  • 135
  • 162
19

With current syntax it looks like this

use_frameworks!
workspace 'myWorkspace'

project 'myiPhone'
project 'sharedStuff/sharedStuff'


target 'myiPhone' do
    project 'myiPhone'
    pod 'MBProgressHUD', '~> 0.6'
end


target 'sharedStuff' do
    project 'sharedStuff/sharedStuff'
    pod 'MBProgressHUD', '~> 0.6'
end
10

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'
Fergal Rooney
  • 1,330
  • 2
  • 18
  • 31
  • You are right about target vs link_with. It seems the build phase that checks the Podfile.lock is not updated correctly so I had to delete it manually and do pod install. Also I realised it's incorrect to link a pod with my main target and with a target that produces a static library that gets linked with my main target since it causes duplicate symbols. This makes sense though and is not a CocoaPods problem. – Mihai Damian Jun 06 '13 at 09:05
  • 1
    @MihaiDamian What did you end up doing regarding the duplicate symbols. Ultimately you want to pods library to be linked only to the main app target, and not the static lib as well. – Wilmar Oct 25 '13 at 08:40
  • 4
    This doesn't work for me. Only the last `link_with` statement is getting honored. So in the above example, the only target linked with `Pods.a` would be "sharedStuff". – bcattle Sep 25 '14 at 08:52
  • @AndreyGordeev I ended up using the [cocoapods-packager](https://github.com/CocoaPods/cocoapods-packager) tool to build a framework from each pod, then I drag those into XCode. I don't use the Cocoapods integration with XCode. If your dependencies support it you could also use the newer package manager [Carthage](https://github.com/Carthage/Carthage) which basically takes this approach. – bcattle Nov 19 '15 at 21:10
7

This is my folder structure

OB
|podfile
|Project1->Project1.xcodeproj
|Project2->Project2.xcodeproj

and this is my podfile inside the OB Folder

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'

workspace 'OB.xcworkspace'
use_frameworks!

# ignore all warnings from all pods
inhibit_all_warnings!

project 'Project1/Project1.xcodeproj'
project 'Project2/Project2.xcodeproj'

abstract_target 'OB' do
    pod 'Alamofire', '~> 4.0'

    target 'Project1' do
        project 'Project1/Project1.xcodeproj'
    end

    target 'SchoolKids' do
        project 'Project2/Project2.xcodeproj'
    end
end

This will add Afnetworking/Alamofire to both projects.If we need a exclusive pod to a particular project then we can do this

 target 'Project1' do
        project 'Project1/Project1.xcodeproj'
        pod 'Alamofire', '~> 4.0'
    end
Rahul Vyas
  • 28,260
  • 49
  • 182
  • 256
2

Thanks to Rahul Vyas 's answer, I finally sucess in my project. My project is in react-native, and I use a git submodules as subproject. So this is my pod file:

workspace 'LuminPDFApp.xcworkspace'
# Uncomment the next line to define a global platform for your project
platform :ios, '9.0'
use_frameworks!

inhibit_all_warnings!

project 'LuminPDFApp.xcodeproj'
project '../submodules/react-native-filepicker/ios/RNFilePicker.xcodeproj'

abstract_target 'LuminPDFApp' do
    pod 'SwiftyDropbox'

    target 'LuminPDFApp' do
        project 'LuminPDFApp.xcodeproj'
    end

    target 'RNFilePicker' do
        project '../submodules/react-native-filepicker/ios/RNFilePicker.xcodeproj'
    end
end
loc
  • 21
  • 4