Cocoapods: How to remove a file From CocoaPods to avoid duplicates?

Created on 3 Feb 2015  路  2Comments  路  Source: CocoaPods/CocoaPods

I have duplicates with one file that my pods import. I've seen this answer: Prevent Duplicate symbols But I have a lot of error when I run the pod install. I just want to remove one file that I use in a static Library too.. I have the problem with GTMHttpFetcher.m file when I import the GoogleOpenSource.framework. I've tried to use cocoa pods for this framework. But I have problems too..

I have tried adding this to de Podfile:

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 == 'GTMHTTPFetcher.m'
    end
    puts "Deleting source file #{dummy.inspect} from target #{target.inspect}."
    source_files.delete(dummy)
  end
end

I am getting this error:

Deleting source file nil from target <PBXNativeTarget name=`Pods-500px-iOS-api` UUID=`092423F52F17EEBFBB2A17A2`>.
[!] An error occurred while processing the post-install hook of the Podfile.

undefined method `remove_referrer' for nil:NilClass

/Library/Ruby/Gems/2.0.0/gems/xcodeproj-0.20.2/lib/xcodeproj/project/object_list.rb:206:in `block in perform_deletion_operations'
/Library/Ruby/Gems/2.0.0/gems/xcodeproj-0.20.2/lib/xcodeproj/project/object_list.rb:205:in `each'
/Library/Ruby/Gems/2.0.0/gems/xcodeproj-0.20.2/lib/xcodeproj/project/object_list.rb:205:in `perform_deletion_operations'
/Library/Ruby/Gems/2.0.0/gems/xcodeproj-0.20.2/lib/xcodeproj/project/object_list.rb:113:in `delete'
/Users/croigsalvador/minube-iOS/Podfile:57:in `block (3 levels) in from_ruby'
/Users/croigsalvador/minube-iOS/Podfile:49:in `each'
/Users/croigsalvador/minube-iOS/Podfile:49:in `block (2 levels) in from_ruby'
/Library/Ruby/Gems/2.0.0/gems/cocoapods-core-0.35.0/lib/cocoapods-core/podfile.rb:164:in `call'
/Library/Ruby/Gems/2.0.0/gems/cocoapods-core-0.35.0/lib/cocoapods-core/podfile.rb:164:in `post_install!'
/Library/Ruby/Gems/2.0.0/gems/cocoapods-0.35.0/lib/cocoapods/installer.rb:553:in `run_podfile_post_install_hook'
/Library/Ruby/Gems/2.0.0/gems/cocoapods-0.35.0/lib/cocoapods/installer.rb:541:in `block in run_podfile_post_install_hooks'
/Library/Ruby/Gems/2.0.0/gems/cocoapods-0.35.0/lib/cocoapods/user_interface.rb:110:in `message'
/Library/Ruby/Gems/2.0.0/gems/cocoapods-0.35.0/lib/cocoapods/installer.rb:540:in `run_podfile_post_install_hooks'
/Library/Ruby/Gems/2.0.0/gems/cocoapods-0.35.0/lib/cocoapods/installer.rb:128:in `block in generate_pods_project'
/Library/Ruby/Gems/2.0.0/gems/cocoapods-0.35.0/lib/cocoapods/user_interface.rb:49:in `section'
/Library/Ruby/Gems/2.0.0/gems/cocoapods-0.35.0/lib/cocoapods/installer.rb:123:in `generate_pods_project'
/Library/Ruby/Gems/2.0.0/gems/cocoapods-0.35.0/lib/cocoapods/installer.rb:92:in `install!'
/Library/Ruby/Gems/2.0.0/gems/cocoapods-0.35.0/lib/cocoapods/command/project.rb:71:in `run_install_with_update'
/Library/Ruby/Gems/2.0.0/gems/cocoapods-0.35.0/lib/cocoapods/command/project.rb:101:in `run'
/Library/Ruby/Gems/2.0.0/gems/claide-0.7.0/lib/claide/command.rb:271:in `run'
/Library/Ruby/Gems/2.0.0/gems/cocoapods-0.35.0/lib/cocoapods/command.rb:45:in `run'
/Library/Ruby/Gems/2.0.0/gems/cocoapods-0.35.0/bin/pod:43:in `<top (required)>'
/usr/bin/pod:23:in `load'
/usr/bin/pod:23:in `<main>'

Most helpful comment

This was a good starting point for me to remove the symbol duplication with SRWebSocket.m, Please find my working copy of post_install which remove the symbol duplication.

post_install do |installer|
  installer.pods_project.targets.each do |target|
    if target.name == 'SocketRocket'
        source_files = target.source_build_phase.files
        dummy = source_files.find do |file|
            #puts "File: #{file.file_ref.name}"
            file.file_ref.name == 'SRWebSocket.m'
        end
        source_files.delete dummy
        puts "Deleting source file #{dummy.inspect} from target #{target.inspect}."
    end
  end
end

All 2 comments

This is better off on the Stack Overflow or the mailing list, but from the looks of the code you're not checking if that file exists in the current target.

This was a good starting point for me to remove the symbol duplication with SRWebSocket.m, Please find my working copy of post_install which remove the symbol duplication.

post_install do |installer|
  installer.pods_project.targets.each do |target|
    if target.name == 'SocketRocket'
        source_files = target.source_build_phase.files
        dummy = source_files.find do |file|
            #puts "File: #{file.file_ref.name}"
            file.file_ref.name == 'SRWebSocket.m'
        end
        source_files.delete dummy
        puts "Deleting source file #{dummy.inspect} from target #{target.inspect}."
    end
  end
end
Was this page helpful?
0 / 5 - 0 ratings