Avoid duplicate symbols with static library and cocoapods
Third party static libraries should never link other third party static libraries themselves. All libraries should be linked together at the end by the final application link step. If the cocoapod spec is calling for one static library to include another, then it is incorrect and needs to be fixed.
For more on this, see this question, as well as the questions it links:
ObjC: How to compile static library that includes optional classes that depend on a third party library
Prevent duplicate symbols when building static library with Cocoapods
In short, the only good way of distributing prebuilt libraries is by not including any of the dependencies, but leaving that up to the user. I.e. in your example, you would instruct your users how to also add AFNetworking to their project. The same basically applies regarding the dummy
files.
Having said that, you could of course go for multiple prebuilt variants:
- Include all dependencies.
- Only include your lib’s source, leave dependencies up to the user.
We have been talking about creating a plugin to produce standalone static libraries, for the purpose that you want, but that’s as of yet not started and will probably take a little while longer. (Until someone/anyone has the time.)
As a workaround, you could use your Podfile’s post_install
hook to remove the dummy files altogether. (these are only needed for non-source libs like Testflight anyways.) E.g. something like the following:
post_install do |installer|
installer.project.targets.each do |target|
source_files = target.source_build_phase.files
dummy = source_files.find do |file|
# TODO Fix this to the actual filename
# puts "File: #{file.file_ref.name}"
file.file_ref.name == 'TheDummyFile.m'
end
puts "Deleting source file #{dummy.inspect} from target #{target.inspect}."
source_files.delete(dummy)
end
end
This is untested code.
The post_install
hook yields the CocoaPods installer object, from which you can get the Pods.xcodeproj targets, for which you can find documentation here. From there you can drill down and do anything you like to the project, which is saved to disk after running this hook.
Related Topics
Differencebetween the App Id and the Bundle Id? Where Is the App Id in the Xcode Project
Frosted Glass (iOS 7 Blur) Effect
Swift Array Append Overwriting Other Array Values
Sizing a Container View with a Controller of Dynamic Size Inside a Scrollview
Gmsgeocoder Reversegeocodecoordinate: Completionhandler: on Background Thread
How to Delete an App from Itunesconnect/App Store Connect
Save an Object in Nsuserdefaults and Realm
Detected a Case Where Constraints Ambiguously Suggest a Height of Zero
Opening a PDF Document When Clicking a Button
Uicollectionview Horizontal Paging - How to Use Flow Layout
Swift:Non-Nil Optional Value Raising a Nil Exception
Uiimageview Aspect Fit and Center
Cordova: Start Specific iOS Emulator Image
Change Uitextfield and Uitextview Cursor/Caret Color
Over the Air (Ota) iOS IPA File Distribution for Public
Cannot Assign Value of Type '() -> Void' to Type '(() -> Void)!'
How to Upload Audio with Alamofire Multipart Upload
How to Obtain Country, State, City from Reversegeocodecoordinate