Aus*_*tin 136 xcode target cocoapods
我在我的Xcode 4项目中使用CocoaPods,我的项目有三个目标(默认情况下,一个用于构建精简版本,一个用于构建演示版本).所有目标都使用相同的库,但CocoaPods只是将静态库和搜索路径添加到主目标.我的podfile看起来像这样:
platform :ios, '5.0'
pod 'TestFlightSDK', '>= 1.1'
pod 'MBProgressHUD', '0.5'
pod 'iRate', '>= 1.6.2'
pod 'TimesSquare', '1.0.1'
pod 'AFNetworking', '1.1.0'
pod 'KKPasscodeLock', '0.1.5'
pod 'iCarousel', '1.7.4'
Run Code Online (Sandbox Code Playgroud)
我得到这个工作的唯一方法是单独指定每个目标,再次列出所有的pod.
platform :ios, '5.0'
target :default do
pod 'TestFlightSDK', '>= 1.1'
pod 'MBProgressHUD', '0.5'
pod 'iRate', '>= 1.6.2'
pod 'TimesSquare', '1.0.1'
pod 'AFNetworking', '1.1.0'
pod 'KKPasscodeLock', '0.1.5'
pod 'iCarousel', '1.7.4'
end
target :lite do
link_with 'app-lite'
pod 'TestFlightSDK', '>= 1.1'
pod 'MBProgressHUD', '0.5'
pod 'iRate', '>= 1.6.2'
pod 'TimesSquare', '1.0.1'
pod 'AFNetworking', '1.1.0'
pod 'KKPasscodeLock', '0.1.5'
pod 'iCarousel', '1.7.4'
end
target :demo do
link_with 'app-demo'
pod 'TestFlightSDK', '>= 1.1'
pod 'MBProgressHUD', '0.5'
pod 'iRate', '>= 1.6.2'
pod 'TimesSquare', '1.0.1'
pod 'AFNetworking', '1.1.0'
pod 'KKPasscodeLock', '0.1.5'
pod 'iCarousel', '1.7.4'
end
Run Code Online (Sandbox Code Playgroud)
有一个更好的方法吗?
Kei*_*ley 318
CocoaPods 1.0已经改变了这个的语法.它现在看起来像这样:
def shared_pods
pod 'SSKeychain', '~> 0.1.4'
pod 'INAppStoreWindow', :head
pod 'AFNetworking', '1.1.0'
pod 'Reachability', '~> 3.1.0'
pod 'KSADNTwitterFormatter', '~> 0.1.0'
pod 'MASShortcut', '~> 1.1'
pod 'MagicalRecord', '2.1'
pod 'MASPreferences', '~> 1.0'
end
target 'Sail' do
shared_pods
end
target 'Sail-iOS' do
shared_pods
end
Run Code Online (Sandbox Code Playgroud)
OUTDATED Pre CocoaPods 1.0回答:
是的,还有更好的方法!看看link_with哪里可以做link_with 'MyApp', 'MyOtherApp'指定多个目标.
我使用它来进行单元测试link_with 'App', 'App-Tests'(谨防目标名称中的空格).
例:
platform :osx, '10.8'
link_with 'Sail', 'Sail-Tests'
pod 'SSKeychain', '~> 0.1.4'
pod 'INAppStoreWindow', :head
pod 'AFNetworking', '1.1.0'
pod 'Reachability', '~> 3.1.0'
pod 'KSADNTwitterFormatter', '~> 0.1.0'
pod 'MASShortcut', '~> 1.1'
pod 'MagicalRecord', '2.1'
pod 'MASPreferences', '~> 1.0'
Run Code Online (Sandbox Code Playgroud)
您可以使用abstract_target
# Note: There are no targets called "Shows" in any of this workspace's Xcode projects
abstract_target 'Shows' do
pod 'ShowsKit'
# The target ShowsiOS has its own copy of ShowsKit (inherited) + ShowWebAuth (added here)
target 'ShowsiOS' do
pod 'ShowWebAuth'
end
# The target ShowsTV has its own copy of ShowsKit (inherited) + ShowTVAuth (added here)
target 'ShowsTV' do
pod 'ShowTVAuth'
end
# Our tests target has its own copy of
# our testing frameworks, and has access
# to ShowsKit as well because it is
# a child of the abstract target 'Shows'
target 'ShowsTests' do
inherit! :search_paths
pod 'Specta'
pod 'Expecta'
end
end
Run Code Online (Sandbox Code Playgroud)
Ada*_*G J 88
我认为更好的解决方案是
# Podfile
platform :ios, '8.0'
use_frameworks!
# Available pods
def available_pods
pod 'AFNetworking', '1.1.0'
pod 'Reachability', '~> 3.1.0'
end
target 'demo' do
available_pods
end
target 'demoTests' do
available_pods
end
Run Code Online (Sandbox Code Playgroud)
参考来自:http://natashatherobot.com/cocoapods-installing-same-pod-multiple-targets/
如果要多个目标共享相同的Pod,请使用abstract_target。
# There are no targets called "Shows" in any Xcode projects
abstract_target 'Shows' do
pod 'ShowsKit'
pod 'Fabric'
# Has its own copy of ShowsKit + ShowWebAuth
target 'ShowsiOS' do
pod 'ShowWebAuth'
end
# Has its own copy of ShowsKit + ShowTVAuth
target 'ShowsTV' do
pod 'ShowTVAuth'
end
end
Run Code Online (Sandbox Code Playgroud)
要不就
pod 'ShowsKit'
pod 'Fabric'
# Has its own copy of ShowsKit + ShowWebAuth
target 'ShowsiOS' do
pod 'ShowWebAuth'
end
# Has its own copy of ShowsKit + ShowTVAuth
target 'ShowsTV' do
pod 'ShowTVAuth'
end
Run Code Online (Sandbox Code Playgroud)
来源:https : //guides.cocoapods.org/using/the-podfile.html
| 归档时间: |
|
| 查看次数: |
63122 次 |
| 最近记录: |