我正在准备一个支持OS X和iOS的Pod。我的Pod有自己的一些依赖项,这些依赖项在podspec文件中定义,因此我使用Podfile来管理开发Pod和运行测试所用项目的依赖关系。我正在使用CocoaPods 0.33.1。
我有4个目标:
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
错误:
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文档,但在这方面发现它不足。