为具有多个目标和不同平台的项目编写Podfile [英] Writing a Podfile for a project with multiple targets and different platforms

查看:75
本文介绍了为具有多个目标和不同平台的项目编写Podfile的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正准备一个支持OS X和iOS的pod。我的pod有自己的一些依赖项,它们在podspec文件中定义,所以我使用Podfile来管理我用来开发pod并运行测试的项目的依赖项。我正在使用CocoaPods 0.33.1。

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.

我有四个目标:


  • MFDynamic.iOS (iOS静态库)

  • MFDynamic.iOS.Tests (iOS测试包)

  • MFDynamic.Mac (Mac框架)

  • MFDynamic.Mac.Tests (Mac测试包)

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

我想要的行为是这个:


  • 指定每个目标的平台(因为有iOS和OS X目标)。

  • 将podspec依赖项作为pod包含在非测试目标中。

  • 能够指定 Kiwi / XCTest 作为我的测试的依赖项仅限目标。

  • 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.

但是,无论我尝试过什么,我都无法编写可行的Podfile。 / strong>运行 pod install 永远不会将CocoaPods的构建阶段添加到我的目标,也不会添加相应的 xcconfig 文件到项目。 CocoaPods没有输出关于Podfile中任何错误的警告。

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

我甚至考虑将所有目标链接到所有目标,如当项目通过CocoaPods包含在别人的工作中时,它只会抓取相应的源文件。因此,即使说,Kiwi与iOS静态库目标相关联,在与CocoaPods集成时也不会将其拖入用户的项目中。我真的很想避免这种做法,但如果这是唯一的方法......

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'

在这种情况下,我得到一个 pod install 错误:

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



我的问题:



做我想做的正确方法是什么(见上文)?如何让CocoaPods成功集成到我的项目和iOS / Mac目标中?我已经仔细阅读了Podfile文档,但发现它在这方面缺乏。

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.

推荐答案

知道了!正如我想的那样,滥用Podfile语法导致

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

相反,这是因为我手动清理了我所有与CocoaPods相关的东西的构建阶段执行干净的 pod安装(不要问为什么)。

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).

看了一下 CocoaPods源代码,我注意到当目标的Link Binary With Libraries构建阶段中存在pods静态库时,会跳过集成到目标中。哎呀!

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!

从我的每个目标中删除 libPods-xxxx.a 文件并运行 pod install 再次执行集成到我的目标。

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

这篇关于为具有多个目标和不同平台的项目编写Podfile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆