Multiple projects in a Workspace? #79

Closed
bonkowski opened this Issue Nov 18, 2011 · 41 comments
@bonkowski

Hi.

I want to use CocoaPods on our new project, but I think I'm missing something. I want to have one Workspace containing a couple of projects, but it seems that CocoaPods does not support this.

Whenever I run pod install AppName.xcodeproj it generates a new workspace called AppName.xcworkspace and tells me to use this from now on. But what about the existing workspace? And how can I add additional CocoaPods based project to the same workspace?

Thanks

@alloy
CocoaPods member

It certainly can be done, it’s only the part that configures your project which is a bit naive. I.e. it currently caters to the simplest common case, which is one app project.

For now you’ll have to configure each project that you will add to the workspace manually as described in the ‘What this does’ section.

Will each project require a different set of dependencies? If so, you’ll have to define targets as described in the ‘Multiple targets’ section.

All in all, we are still refining the process of configuring the projects for you. It would help greatly if you can explain a bit more about your setup and explain what you had to perform manually to configure it to work.

@bonkowski

Our project is a "one app project", at least for now, having one workspace containing two projects. The first project is a "API" project which is linked in to the other project, which use the API projects services. Other projects will possibly be added later that also is going to use the API services.

@alloy
CocoaPods member

Are the Pods dependencies of the API project, app project, or both (different sets of dependencies)?

(CC'ing @lukeredpath as he has experience with a similar setup.)

@bonkowski

Funny that you added @lukeredpath to the discussion since the library I wanted to add to the project when I found CocoaPods was Kiwi :-)

The API project have dependencies to AFNetworking and JSONKit, and the "other" project has dependencies to a mapviewer library and the API project. Both will depend on Kiwi.

@alloy
CocoaPods member

This will be interesting :)

So basically your Podfile should look something like the following (non-functional example):

target 'API', :exclusive => true do
  link_with 'API lib', :project => 'API Project'

  dependency 'AFNetworking'

  target 'API-test' do
    link_with 'API test', :project => 'API Project'
    dependency 'Kiwi'
  end
end

target 'other', :exclusive => true do
  link_with 'Other target', :project => 'Other Project'

  dependency 'SomeMapViewer'

  target 'other-test' do
    link_with 'Other test', :project => 'Other Project'
    dependency 'Kiwi'
  end
end

This means that:

  • We’ll have to ensure (or fix) that you can have target groups depend on the outer exclusive target group.
  • Allow an optional project attribute for link_with, to specify the project in the workspace. Although if the target name is unique we should be able to figure it out without specifying the project name.
  • We should probably not generate the default target if no dependencies are specified for it. An empty libPods.a is useless and confusing.
  • You will have to add the API library to the ‘other project’ link build phase yourself and there may be a need to do some xcconfig munging.

Does this seem like the correct config for you scenario?

@bonkowski

Let me first say that I'm not very experienced with Xcode4 and the build settings, but as far as I can see this could work.
Shouldn't the 'other' target have a dependency to 'API'?

@alloy
CocoaPods member

Regarding the xcconfig munging, it might be a good idea to generate two files per target. One which defines the actual values, but with namespaced keys and the actual xcconfig file which just imports the other one and assigns the values to the actual keys. This will allow the user to create aggregate configs from multiple target configs easily.

Target 1

Pods-definitions.xcconfig:

USER_HEADER_SEARCH_PATHS-Pods = "Pods/AFNetworking"

Pods-test.xcconfig:

#include "Pods-definitions.xcconfig"
USER_HEADER_SEARCH_PATHS = USER_HEADER_SEARCH_PATHS-Pods

Target 2

Pods-test-definitions.xcconfig:

USER_HEADER_SEARCH_PATHS-Pods-test = "Pods/Kiwi"

Pods-test.xcconfig:

#include "Pods-test-definitions.xcconfig"
USER_HEADER_SEARCH_PATHS = USER_HEADER_SEARCH_PATHS-Pods-test

Custom aggregate target

Say the user now wants to use both the Pods libs in one target, then they can easily combine the configs like so:

CustomAggregate.xcconfig:

#include "Pods-definitions.xcconfig"
#include "Pods-test-definitions.xcconfig"
USER_HEADER_SEARCH_PATHS = $(USER_HEADER_SEARCH_PATHS-Pods) $(USER_HEADER_SEARCH_PATHS-Pods-test)

NOTE this is untested, but from reading about xcconfig files I think this is the way they work

@alloy
CocoaPods member

Shouldn't the 'other' target have a dependency to 'API'?

The name was getting a bit ambiguous, there are two libs involved in the API project. :)

In this case I meant that the API Pods lib will be linked to your API project’s product lib. Although it’s a lib as well, it’s outside of the scope of CocoaPods, so you will have to add that product lib to the ‘other’ project yourself.

@bonkowski

Wow! I'll think I have to spend some time this weekend get get a better grip on xcconfig :-)

@alloy
CocoaPods member

This thread might help to understand what I just described :)

Anyways, to be able to help your situation out as soon as possible, I think the most important thing is that nested targets work as shown in that example. All other things can be configured by hand (and configuring your projects to use the Pods libs is usually done only once). I’ll try to get this out tonight/tomorrow.

@alloy alloy added a commit that closed this issue Nov 18, 2011
@alloy alloy Don’t create a target if its definition, in the Podfile, is empty (no…
… dependencies). Closes #79.
6b68f52
@alloy alloy closed this in 6b68f52 Nov 18, 2011
@alloy alloy reopened this Nov 18, 2011
@alloy
CocoaPods member

This is not actually fixed yet. Need to ensure we have separate tickets for the individual issues.

@alloy
CocoaPods member

Ok, I think that when this fix is released (0.3.5), you should at least be able to do it, although you’d still have to do the hooking up to your projects targets yourself. (#76 & #80 describe the issues related to configuring projects.)

Let me know if I missed anything or you run into problems configuring the projects manually.

@alloy alloy closed this Nov 18, 2011
@bonkowski

Thanks a lot. I'll try and come back to you.

@bonkowski

Hello again.

I have read your comments and the examples several times, but I still don't understand how to create a workspace with more than one project.

Let say I want to have three projects in one workspace. App1, App2 and a API project which is used by both App1 and App2. Each of the projects can of course have dependencies to other libraries.

An example on how to solve this would be much appreciated.

Thanks...

@alloy
CocoaPods member

I think it might be best to wait till we have support for the aforementioned link_with helper and allow xcconfig files to be mixed. Then I’ll create an example app too to illustrate this.

@alloy alloy reopened this Nov 21, 2011
@bonkowski

No problem, I'll wait :-)

@alloy
CocoaPods member

Closed by 23626ca.

@alloy alloy closed this Apr 13, 2012
@tonyxiao

Is there an example project on how to put accomplish this multi-project per workspace setup?

@alloy
CocoaPods member

@tonyxiao If the target names match those in your projects, than it should automagically work. Otherwise you will have to specify the project inside the target block like so:

target 'My Target' do
  xcodeproj 'My Project'
end
@tonyxiao

I tried using the following Podspec, then ran pod install, but it seems to have no effect.

platform :osx, '10.7'
workspace 'MyProj.xcworkspace'

inhibit_all_warnings!

pod 'AFNetworking'
pod 'RestKit', '0.10.1'
pod 'ConciseKit', '0.1.2'
#pod 'BlocksKit', '1.5.0'
pod 'NSLogger', :podspec => 'local'

target 'MyProj' do
  xcodeproj 'MyProj.xcodeproj'
end

target 'MyPlugin' do
  xcodeproj 'Plugins/MyPlugin/MyPlugin.xcodeproj'
end

I'm trying to accomplish a setup where a plugin app is in the same workspace is the primary app and have mostly the same dependencies. I've tried to manually add libPods.a to linked libraries, and created a PluginPods.xcconfig file as follow in the Plugins directory.

#include "../Pods/Pods.xcconfig"
PODS_ROOT = ${SRCROOT}/../../Pods

This seems to work, except it feels error prone and lacks a Copy Pods Resources build phase that executes the shell script "${SRCROOT}/Pods/Pods-resources.sh". I was hoping that perhaps there are built in support in the Podfile to accommodate setup.

@alloy
CocoaPods member

I see. The two targets don’t contain any dependencies of their own, only inherited ones. For this reason they are considered empty and being ignored… Can you confirm this by adding an extra dependency to one of the targets and see if it does work then?

@tonyxiao

Ah, that seems to finally have some effect and modifies the projects. Now I get a libPods-MyProj.a and a libPods-MyPlugin.a library. My Podfile looks like this

platform :osx, '10.7'
workspace 'MyProj.xcworkspace'

inhibit_all_warnings!

pod 'AFNetworking'
pod 'RestKit', '0.10.1'
#pod 'BlocksKit', '1.5.0'
pod 'NSLogger', :podspec => 'local'

target 'MyProj' do
  xcodeproj 'MyProj.xcodeproj'

  pod 'ConciseKit', '0.1.2'
end

target 'MyPlugin' do
  xcodeproj 'Plugins/MyPlugin/MyPlugin.xcodeproj'

  pod 'ConciseKit', '0.1.2'
end

However, I'm not getting errors in my project that says ConciseKit/ConciseKit.h not found. Additionally, Is it possible to specify a set of pods that apply to an entire project rather than just specific targets? Pods that apply to targets can inherit from pods that apply to an entire project. Something along the lines of the following

platform :osx, '10.7'
workspace 'MyProj.xcworkspace'

inhibit_all_warnings!

pod 'AFNetworking'
pod 'RestKit', '0.10.1'
#pod 'BlocksKit', '1.5.0'
pod 'NSLogger', :podspec => 'local'

xcodeproj 'MyProj.xcodeproj' do
  pod 'ConciseKit', '0.1.2'

  target 'MyProj' do
    pod 'Mixpanel'
  end

  target 'MyProjTests' do
    pod 'Kiwi'
  end

end

xcodeproj 'Plugins/MyPlugin/MyPlugin.xcodeproj' do

  pod 'ConciseKit', '0.1.2'

  target 'MyPlugin' do
    pod 'Mixpanel'
  end

  target 'MyPluginTests' do
    pod 'Kiwi'
  end

end
@dperetti

This doesn't seem to work. Can we reopen this ticket ?

@krawftyone

I tired this myself with no success. Can you reopen this ticket or post a podfile that works?

I am trying to have multiple projects in one podfile with different pods.

@GWStuartClift

@krawftyone See #738 (comment) there is an example by @dperetti showing what he found does and does not work.

@mave99a

Yes, this need to re-opened since it's not working as expected.

@marquezzy

I am having the same problem as well. Would love to get some information on how to proceed from here.

@fabiopelosin
CocoaPods member

@marquezzy Can you post your Podfile and describe the exact issue?

@marquezzy

@irrationalfab

The podfile is super simple.


platform :ios, '5.0'
pod 'AFNetworking', :head

I already have a workspace for my project with four static libraries added as additional projects in the workspace. When I run pod install my existing projects are removed from the workspace. The references are there in red indicating something is missing. I was able to work around it by re-adding them to the workspace and add libPods to my build scheme.

I received an error:


[!] The target MyAppName [Debug - Release - Distribution]' overrides theALWAYS_SEARCH_USER_PATHS' build setting defined in Pods/Pods.xcconfig'.
- Use the
$(inherited)' flag, or
- Remove the build settings from the target.

[!] The target MyAppName [Debug - Release - Distribution]' overrides theHEADER_SEARCH_PATHS' build setting defined in Pods/Pods.xcconfig'.
- Use the
$(inherited)' flag, or
- Remove the build settings from the target.

My project builds and runs in the simulator but I am getting file not found for headers in my projects when archiving. How can I resolve these issues?

@fabiopelosin
CocoaPods member

The podfile is super simple.

You need to specify all the targets that you wan't to integrate with, you also may want to use the xcodeproj and the workspace directives. This documentation should get you on the right track.

I received an error.

You are overriding some of the settings of the xcconfigs generated by CocoaPods and you should edit your build settings as indicated to the warning.

As this is not a bug in CP, please use the mailing list or stack overflow for more clarification.

@marquezzy

@irrationalfab Thanks.

@conqueror

I have a workspace with two projects. First project is a library project and used by second project as a static library.
I want to integrate my workspace with Cocopods. Basically I want to integrate my Library project with Cocoapods and I want to link MyApp to MyLibrary project. I came up with different combinations of Podfile with no success.

My latest Podfile is like this:

platform :ios, '5.1'
workspace 'MyWorkspace.xcworkspace'
xcodeproj 'MyLibraryProj.xcodeproj'

inhibit_all_warnings!

pod 'AFNetworking', '1.3.3'
pod 'JSONKit', '~> 1.4'
pod 'Reachability', '~> 3.1.1'
pod 'TTTAttributedLabel', '~> 1.7.1'
pod 'UrbanAirship-iOS-SDK', '~> 3.0.0'
pod 'ZipArchive', '~> 1.2.0'
pod 'ZXing', '~> 2.1'
pod 'MKNumberBadgeView', '~> 0.0.1'
pod 'SVStatusHUD', '~> 0.0.1'

#link_with 'LibraryProj'

target 'MyApp', :exclusive => true do
platform :ios, '5.1'
xcodeproj 'MyApp.xcodeproj'
pod 'SSToolkit', '~> 1.0.4'
end

@conqueror

I solved the problem and posting my Podfile:

platform :ios, '5.1'
workspace 'MyWorkspace.xcworkspace'
xcodeproj 'MyLibraryProj.xcodeproj'

inhibit_all_warnings!

target 'MyLibraryProj' do
xcodeproj 'MyLibraryProj.xcodeproj'
pod 'NSLogger', '~> 1.1'
pod 'TouchXML', '~> 0.1'
pod 'AFNetworking', '1.3.3'
pod 'JSONKit', '~> 1.4'
pod 'Reachability', '~> 3.1.1'
pod 'TTTAttributedLabel', '~> 1.7.1'
pod 'UrbanAirship-iOS-SDK', '~> 3.0.0'
pod 'ZipArchive', '~> 1.2.0'
pod 'ZXing', '~> 2.1'
pod 'MKNumberBadgeView', '~> 0.0.1'
pod 'SVStatusHUD', '~> 0.0.1'

target 'MyApp', :exclusive => true do
    platform :ios, '5.1'
    xcodeproj 'MyApp.xcodeproj'
    pod 'SSToolkit', '~> 1.0.4'

end

end

Not: in Pods project and all targets change the settings to "Compiler Default" for C++ Language Dialect and C++ Language Library.

@fatuhoku

Thanks a lot! @conqueror it looks like your spec file really has created a workspace with two projects in it. I've been able to set up Kiwi testing for one of those projects at least. Great stuff!

@alloy alloy added a commit that referenced this issue Oct 25, 2014
@alloy alloy Don’t create a target if its definition, in the Podfile, is empty (no…
… dependencies). Closes #79.
bf3e644
@andrew8712

Can anyone provide a valid working podfile for two-project workspace? All of the above are not working.

@andrew8712

Okay, got this working with the following pod file:

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
@segiddins
CocoaPods member

Please don't comment on three year old closed issues.

@andrew8712

@segiddins why not? I googled about this issue and came here. I believe this is how many of us looking for a solution.

@segiddins
CocoaPods member

If you're having an issue, please open one with all of the information requested in the contributing guidelines.

@fatuhoku

... @segiddins I posted a link because I originally got my demo setup working using @andrew8712's code snippet. I was not raising a new issue. I cannot imagine why starting another issue would help anybody.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment