我正在准备一个支持 OS X 和 iOS 的 Pod。我的 pod 有一些自己的依赖项,这些依赖项在 podspec 文件中定义,因此我使用 Podfile 来管理我用来开发 pod 和运行测试的项目的依赖项。我正在使用 CocoaPods 0.33.1。
我有四个目标:
-
MFDynamic.iOS
(iOS静态库)
-
MFDynamic.iOS.Tests
(iOS 测试包)
-
MFDynamic.Mac
(Mac框架)
-
MFDynamic.Mac.Tests
(Mac 测试包)
我想要的行为是这样的:
- 指定每个目标的平台(因为有 iOS 和 OS X 目标)。
- 将 podspec 依赖项作为 pod 包含在非测试目标中。
- 能够指定
Kiwi/XCTest
仅作为我的测试目标的依赖项。
然而,无论我尝试过什么,我都无法编写一个有效的 Podfile。跑步pod install
从来没有将 CocoaPods 的构建阶段添加到我的目标中,也没有添加适当的xcconfig
文件到项目中。 CocoaPods 不会输出有关 Podfile 中任何错误的警告。
这是我最近一次失败的尝试:
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
稍微简化一下会产生相同的结果(即项目中没有集成):
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
我什至会考虑将所有 pod 与所有目标链接起来,因为最终当项目通过 CocoaPods 包含在其他人的工作中时,它只会获取适当的源文件。因此,即使 Kiwi 链接到了 iOS 静态库目标,在与 CocoaPods 集成时也不会被拖入用户的项目中。我真的很想避免这种方法,但如果这是唯一的方法......
不管怎样,带着这种心态,我尝试了以下方法,但运气并不好:
link_with 'MFDynamic.iOS', 'MFDynamic.Mac', 'MFDynamic.iOS.Tests', 'MFDynamic.Mac.Tests'
podspec :path => '../MFDynamic.podspec'
pod 'Kiwi', '~> 2.2'
在这种情况下我得到一个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 文档,但发现它在这方面有所欠缺。