Prevent duplicate symbols when building static library with Cocoapods

后端 未结 6 1392
天涯浪人
天涯浪人 2020-12-07 21:32

While I\'ve seen many questions dealing with Cocoapods and static libraries, most of them seem to assume you\'ll eventually have a single workspace with your static library

6条回答
  •  借酒劲吻你
    2020-12-07 22:06

    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.

提交回复
热议问题