Having the following project structure:
Is this kind of setup supported by CocoaPods?
My first attempt was to do something like this:
platform :ios, '9.0'
use_frameworks!
target 'App' do
workspace 'App.xcworkspace'
project 'App.xcodeproj'
pod 'Material'
end
target 'Framework' do
workspace 'App.xcworkspace'
project 'Framework/Framework.xcodeproj'
pod 'AFNetworking'
end
But the application crashes on launch with the following error:
dyld: Library not loaded: @rpath/AFNetworking.framework/AFNetworking
Referenced from: /Users/ruenzuo/Library/Developer/Xcode/DerivedData/App-aayvulxvruuarudtheuilepmmctk/Build/Products/Debug-iphonesimulator/Framework.framework/Framework
Reason: image not found
Which makes sense, because CocoaPods doesn't know that the App and Framework are related. In fact, after pod install I get the following 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).
I then tried embedding the Framework target into the Application target, like this:
platform :ios, '9.0'
use_frameworks!
target 'App' do
workspace 'App.xcworkspace'
project 'App.xcodeproj'
pod 'Material'
target 'Framework' do
workspace 'App.xcworkspace'
project 'Framework/Framework.xcodeproj'
pod 'AFNetworking'
end
end
But it didn't work. The only way I managed to get it working was like:
platform :ios, '9.0'
use_frameworks!
target 'App' do
workspace 'App.xcworkspace'
project 'App.xcodeproj'
pod 'Material'
pod 'AFNetworking'
end
target 'Framework' do
workspace 'App.xcworkspace'
project 'Framework/Framework.xcodeproj'
pod 'AFNetworking'
end
But having the AFNetworking pod repeated feels like I'm doing something wrong. Also, I didn't manage to get rid of the warning, so obviously I'm just forcing this to work by having CocoaPods copying over the AFNetworking pod to the application Frameworks directory.
Has anyone managed to get something like this working?
use_frameworks! in the Podfile means that we want the listed frameworks to be dynamically installed instead as static frameworks. Thank you but please give more details about dynamically install vs static install.
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.
The trick is to add your framework target to the "Target Dependencies" build phase of your application target, like this:
For some reason CocoaPods relies on "Target Dependencies" – it's not enough to have your library/framework in the "Link With Binary Libraries" phase. Your Podfile
should look like this:
project 'CocoapodsTest'
target 'CocoapodsTest' do
pod 'AFNetworking'
end
target 'SampleLibrary' do
pod 'Masonry'
end
After running pod install
, you can inspect the "Other Linker Flags" of your application target to verify that it forwards both your app's and your libraries' dependencies to the linker:
If 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