Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing a Podfile for a project with multiple targets and different platforms

I am preparing a pod that supports OS X and iOS. My pod has some dependencies of its own, which are defined in the podspec file, so I'm using a Podfile to manage the dependencies of the project that I'm using to develop the pod and run tests. I'm using CocoaPods 0.33.1.

I have four targets:

  • MFDynamic.iOS (iOS static library)
  • MFDynamic.iOS.Tests (iOS test bundle)
  • MFDynamic.Mac (Mac framework)
  • MFDynamic.Mac.Tests (Mac test bundle)

The behaviour I want is this:

  • Specify the platform per target (as there are iOS and OS X targets).
  • Include the podspec dependencies as pods in the non-test targets.
  • Being able to specify Kiwi/XCTest as a dependency for my test targets only.

However, I haven't been able to write a Podfile that works, whatever I have tried. Running pod install never adds CocoaPods' build phases to my targets, nor does it add the appropriate xcconfig files to the project. CocoaPods outputs no warning about anything being wrong in the Podfile.

Here is my most recent failed attempt:

target 'MFDynamic.iOS' do
  platform :ios, '6.1'
  podspec :path => '../MFDynamic.podspec'
end

target 'MFDynamic.Mac' do
  platform :osx, '10.7'
  podspec :path => '../MFDynamic.podspec'
end

target 'MFDynamic.iOS.Tests' do
  platform :ios, '6.1'
  pod 'Kiwi/XCTest', '~> 2.2.4'
end

target 'MFDynamic.Mac.Tests' do
  platform :osx, '10.7'
  pod 'Kiwi/XCTest', '~> 2.2.4'
end

Simplifying that a bit yields the same results (i.e. no integration in project):

target 'MFDynamic.iOS' do
  platform :ios, '6.1'
  pod 'AFNetworking', '~> 2.2'
end

target 'MFDynamic.Mac' do
  platform :osx, '10.7'
  pod 'AFNetworking', '~> 2.2'
end

I'd even consider linking all pods against all targets as in the end when the project gets included in someone else's work through CocoaPods it only grabs the appropriate source files. So even if say, Kiwi is linked to the iOS static library target, it won't be dragged into the user's project when integrated with CocoaPods. I'd really like to avoid that approach, but if it's the only way...

Anyway, with that mindset I have tried the following, with not much more luck:

link_with 'MFDynamic.iOS', 'MFDynamic.Mac', 'MFDynamic.iOS.Tests', 'MFDynamic.Mac.Tests'

podspec :path => '../MFDynamic.podspec'
pod 'Kiwi', '~> 2.2'

In that case I get a pod install error:

NoMethodError - undefined method `include?' for nil:NilClass
/Users/Michael/.rvm/gems/ruby-2.0.0-p0/gems/xcodeproj-0.17.0/lib/xcodeproj/project/object/native_target.rb:95:in `platform_name'
/Users/Michael/.rvm/gems/ruby-2.0.0-p0/gems/cocoapods-0.33.1/lib/cocoapods/installer/analyzer.rb:471:in `block in compute_platform_for_target_definition'
/Users/Michael/.rvm/gems/ruby-2.0.0-p0/gems/cocoapods-0.33.1/lib/cocoapods/installer/analyzer.rb:469:in `each'
/Users/Michael/.rvm/gems/ruby-2.0.0-p0/gems/cocoapods-0.33.1/lib/cocoapods/installer/analyzer.rb:469:in `compute_platform_for_target_definition'
/Users/Michael/.rvm/gems/ruby-2.0.0-p0/gems/cocoapods-0.33.1/lib/cocoapods/installer/analyzer.rb:519:in `block in compute_target_platforms'
/Users/Michael/.rvm/gems/ruby-2.0.0-p0/gems/cocoapods-0.33.1/lib/cocoapods/installer/analyzer.rb:514:in `each'
/Users/Michael/.rvm/gems/ruby-2.0.0-p0/gems/cocoapods-0.33.1/lib/cocoapods/installer/analyzer.rb:514:in `compute_target_platforms'
/Users/Michael/.rvm/gems/ruby-2.0.0-p0/gems/cocoapods-0.33.1/lib/cocoapods/installer/analyzer.rb:55:in `analyze'
/Users/Michael/.rvm/gems/ruby-2.0.0-p0/gems/cocoapods-0.33.1/lib/cocoapods/installer.rb:176:in `analyze'
/Users/Michael/.rvm/gems/ruby-2.0.0-p0/gems/cocoapods-0.33.1/lib/cocoapods/installer.rb:98:in `block in resolve_dependencies'
/Users/Michael/.rvm/gems/ruby-2.0.0-p0/gems/cocoapods-0.33.1/lib/cocoapods/user_interface.rb:52:in `section'
/Users/Michael/.rvm/gems/ruby-2.0.0-p0/gems/cocoapods-0.33.1/lib/cocoapods/installer.rb:97:in `resolve_dependencies'
/Users/Michael/.rvm/gems/ruby-2.0.0-p0/gems/cocoapods-0.33.1/lib/cocoapods/installer.rb:89:in `install!'
/Users/Michael/.rvm/gems/ruby-2.0.0-p0/gems/cocoapods-0.33.1/lib/cocoapods/command/project.rb:40:in `run_install_with_update'
/Users/Michael/.rvm/gems/ruby-2.0.0-p0/gems/cocoapods-0.33.1/lib/cocoapods/command/project.rb:70:in `run'
/Users/Michael/.rvm/gems/ruby-2.0.0-p0/gems/claide-0.6.1/lib/claide/command.rb:281:in `run'
/Users/Michael/.rvm/gems/ruby-2.0.0-p0/gems/cocoapods-0.33.1/lib/cocoapods/command.rb:48:in `run'
/Users/Michael/.rvm/gems/ruby-2.0.0-p0/gems/cocoapods-0.33.1/bin/pod:33:in `<top (required)>'
/Users/Michael/.rvm/gems/ruby-2.0.0-p0/bin/pod:23:in `load'
/Users/Michael/.rvm/gems/ruby-2.0.0-p0/bin/pod:23:in `<main>'
/Users/Michael/.rvm/gems/ruby-2.0.0-p0/bin/ruby_executable_hooks:15:in `eval'
/Users/Michael/.rvm/gems/ruby-2.0.0-p0/bin/ruby_executable_hooks:15:in `<main>'

My Question:

What is the correct approach to do what I want (see above)? How can I get CocoaPods to integrate successfully into my project and iOS / Mac targets? I have perused the Podfile documentation but found it lacking in that regard.

like image 330
Form Avatar asked May 28 '14 21:05

Form


People also ask

What does platform mean in Podfile?

It specifies the minimum OS version you are going to support for the pod project. If your applications project's deployment target is less than the pod project mentioned iOS version, you will get a warning if there any any APIs which are deprecated in the supported OS versions in the main project.


1 Answers

Got it! It was not caused by a misuse of the Podfile syntax as I thought.

Rather, it was due to the fact that I had manually cleaned up my build phases of all CocoaPods-related stuff to perform a clean pod install (don't ask why).

After taking a look at the CocoaPods source code, I noticed that integration into a target is skipped when the pods static library is present in the "Link Binary With Libraries" build phase of a target. Whoops!

Removing the libPods-xxxx.a files from each of my targets and running pod install again performed the integration into my targets.

like image 169
Form Avatar answered Oct 18 '22 20:10

Form