First of all, I've turned on use_framework! in Podfile.
首先,我打开了use_framework!在Podfile中。
Assume the main project is MAIN_APP, and two subprojects are FRAMEWORK_A and FRAMEWORK_B.
假设主项目是MAIN_APP,两个子项目是FRAMEWORK_A和FRAMEWORK_B。
MAIN_APP requires FRAMEWORK_A and FRAMEWORK_B, and FRAMEWORK_B requires FRAMEWORK_A as well.
MAIN_APP需要FRAMEWORK_A和FRAMEWORK_B,FRAMEWORK_B也需要FRAMEWORK_A。
All projects/targets are using CocoaPods to manage third party libraries.
所有项目/目标都使用CocoaPods来管理第三方库。
For now, my Podfile looks like:
现在,我的Podfile看起来像:
target :MAIN_APP do
project 'MAIN_APP'
pod 'PodA'
end
target :FRAMEWORK_A do
project 'FRAMEWORK_A'
pod 'PodB'
end
target :FRAMEWORK_B do
project 'FRAMEWORK_B'
pod 'PodC'
end
I manually added FRAMEWORK_A to build settings of FRAMEWORK_B, and both FRAMEWORK_A and FRAMEWORK_B to build settings of MAIN_APP.
我手动添加了FRAMEWORK_A来构建FRAMEWORK_B的设置,以及FRAMEWORK_A和FRAMEWORK_B来构建MAIN_APP的设置。
All code compiles well, but when running the MAIN_APP crashes because it cannot load Framework of PodB.
所有代码都编译得很好,但是在运行MAIN_APP时崩溃是因为它无法加载PodB的Framework。
I know I can manually add PodB to MAIN_APP and FRAMEWORK_B as well, but is it possible to define this kind of target dependency in Podfile?
我知道我也可以手动将PodB添加到MAIN_APP和FRAMEWORK_B,但是可以在Podfile中定义这种目标依赖吗?
Btw, when pod install
, I got the warning:
顺便说一句,当pod安装时,我收到了警告:
[!] The Podfile contains framework targets, for which the Podfile does not contain host targets (targets which embed the framework).
[!] Podfile包含框架目标,Podfile不包含主机目标(嵌入框架的目标)。
If this project is for doing framework development, you can ignore this message. Otherwise, add a target to the Podfile that embeds these frameworks to make this message go away (e.g. a test target).
如果此项目用于框架开发,则可以忽略此消息。否则,将目标添加到嵌入这些框架的Podfile中,以使此消息消失(例如测试目标)。
As I know, I can use nested target for host targets like:
据我所知,我可以使用嵌套目标作为主机目标,如:
target :FRAMEWORK_A
target :MAIN_APP
end
end
So CocoaPods will setup MAIN_APP to use FRAMEWORK_A and inherit pod dependencies from FRAMEWORK_A. But seems I cannot do it with multiple dependencies like:
因此CocoaPods将设置MAIN_APP以使用FRAMEWORK_A并从FRAMEWORK_A继承pod依赖项。但似乎我无法做到多个依赖,如:
target :FRAMEWORK_A
target :MAIN_APP
end
end
target :FRAMEWORK_B
target :MAIN_APP
end
end
Because target :MAIN_APP cannot be declared twice.
因为target:MAIN_APP不能声明两次。
Is there any better solutions instead of defining pod dependencies as a function in Podfile and include in all target?
有没有更好的解决方案,而不是将pod依赖项定义为Podfile中的函数并包含在所有目标中?
1 个解决方案
#1
1
This is a great question and I've struggled with a similar situation. This is my PodFile:
这是一个很好的问题,我也遇到了类似的情况。这是我的PodFile:
platform :ios, '8.0'
workspace 'mygreatapp.xcworkspace'
project 'app/MyGreatApp/MyGreatApp.xcodeproj'
project 'platform/MyGreatFramework/MyGreatFramework.xcodeproj'
abstract_target 'This can say whatever you want' do
target 'MyGreatApp' do
project 'app/MyGreatApp/MyGreatApp.xcodeproj'
pod 'AFNetworking', '~> 2.6.0'
pod 'PromiseKit', '~> 1.5'
pod 'PromiseKit/Join'
pod 'KVOController', '~> 1.0'
pod 'FLAnimatedImage', '~> 1.0'
pod 'Crashlytics', '~> 3.3'
pod 'SSZipArchive'
end
target 'MyGreatAppTests' do
project 'app/MyGreatApp/MyGreatApp.xcodeproj'
pod 'OCMock', '~> 3.1'
end
target 'MyGreatFramework' do
project 'platform/MyGreatFramework/MyGreatFramework.xcodeproj'
pod 'SSZipArchive'
end
target 'MyGreatFrameworkTests' do
project 'platform/MyGreatFramework/MyGreatFramework.xcodeproj'
pod 'OCMock', '~> 3.1'
end
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['ENABLE_BITCODE'] = 'NO'
end
end
end
end
As you can see I'm not using frameworks and I use an abstract_target
to group it all together. I wish these kinds of dependencies were easier to do in CocoaPods. I know this doesn't really answer your question but it might be helpful nonetheless.
正如您所看到的,我没有使用框架,而是使用abstract_target将它们组合在一起。我希望这些依赖在CocoaPods中更容易实现。我知道这并没有真正回答你的问题,但它可能会有所帮助。
#1
1
This is a great question and I've struggled with a similar situation. This is my PodFile:
这是一个很好的问题,我也遇到了类似的情况。这是我的PodFile:
platform :ios, '8.0'
workspace 'mygreatapp.xcworkspace'
project 'app/MyGreatApp/MyGreatApp.xcodeproj'
project 'platform/MyGreatFramework/MyGreatFramework.xcodeproj'
abstract_target 'This can say whatever you want' do
target 'MyGreatApp' do
project 'app/MyGreatApp/MyGreatApp.xcodeproj'
pod 'AFNetworking', '~> 2.6.0'
pod 'PromiseKit', '~> 1.5'
pod 'PromiseKit/Join'
pod 'KVOController', '~> 1.0'
pod 'FLAnimatedImage', '~> 1.0'
pod 'Crashlytics', '~> 3.3'
pod 'SSZipArchive'
end
target 'MyGreatAppTests' do
project 'app/MyGreatApp/MyGreatApp.xcodeproj'
pod 'OCMock', '~> 3.1'
end
target 'MyGreatFramework' do
project 'platform/MyGreatFramework/MyGreatFramework.xcodeproj'
pod 'SSZipArchive'
end
target 'MyGreatFrameworkTests' do
project 'platform/MyGreatFramework/MyGreatFramework.xcodeproj'
pod 'OCMock', '~> 3.1'
end
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['ENABLE_BITCODE'] = 'NO'
end
end
end
end
As you can see I'm not using frameworks and I use an abstract_target
to group it all together. I wish these kinds of dependencies were easier to do in CocoaPods. I know this doesn't really answer your question but it might be helpful nonetheless.
正如您所看到的,我没有使用框架,而是使用abstract_target将它们组合在一起。我希望这些依赖在CocoaPods中更容易实现。我知道这并没有真正回答你的问题,但它可能会有所帮助。