24
votes

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.

5
I get the same sort of problem. A solution to this would be nice!fatuhoku

5 Answers

10
votes

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'
22
votes

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
12
votes

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
7
votes

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
2
votes

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