30

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.

1
  • I get the same sort of problem. A solution to this would be nice! Commented Jun 5, 2013 at 16:07

5 Answers 5

27

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
Sign up to request clarification or add additional context in comments.

5 Comments

If your project 2 is a dependency for project 1, wouldn't this result in duplicate symbols?
No. Why this would cause duplicating symbols?
@RahulVyas I don't use this method anymore. Have you resolved the issue? If yes, feel free to edit an answer.
@AndreyGordeev yes the issue was actually my own mistake I was building for device and I didn't included any provision profile.
Also cocoapods now has different mechanism for shared pods. Let me post that as an answer
20

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

Comments

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'

4 Comments

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.
@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.
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".
@AndreyGordeev I ended up using the 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 which basically takes this approach.
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

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.