First of all, I've turned on use_framework! in Podfile.
Assume the main project is MAIN_APP, and two subprojects are FRAMEWORK_A and FRAMEWORK_B.
MAIN_APP requires FRAMEWORK_A and FRAMEWORK_B, and FRAMEWORK_B requires FRAMEWORK_A as well.
All projects/targets are using CocoaPods to manage third party libraries.
For now, my Podfile looks like:
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.
All code compiles well, but when running the MAIN_APP crashes because it cannot load Framework of PodB.
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?
Btw, when pod install
, I got the warning:
[!] The Podfile contains framework targets, for which the Podfile does not contain host targets (targets which embed the framework).
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).
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:
target :FRAMEWORK_A target :MAIN_APP end end target :FRAMEWORK_B target :MAIN_APP end end
Because target :MAIN_APP cannot be declared twice.
Is there any better solutions instead of defining pod dependencies as a function in Podfile and include in all target?
Cocoapods + SPM 🚀 Now your library supports both cocoa pods and SPM.
If you've used CocoaPods before, you probably know that the usual way to get started using it is by running pod init in the directory that contains the . xcproject file. Running this command creates a workspace that CocoaPods can use to manage the dependencies.
After you have initially installed CocoaPods into your project, you can add new dependencies (or remove unused ones) by editing the Podfile. Then simply run pod install again.
This is a great question and I've struggled with a similar situation. This is my 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.
I think you can also get around this by just making FrameworkA
and FrameworkB
into local (static library) pods and it will de-duplicate everything for you and integrate it into the host app properly.
Examples: https://github.com/rob-keepsafe/PodFrameworksIssue
master
branch shows duplicate classes and umbrella frameworks like you havededuped
branch makes the internal dynamic frameworks into local pods (as static libs) to de-dupe and still link in the dependenciesIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With