How can I remove pod links from a specific target in a post_install hook?

Viewed 1101

Background

  1. Had an existing iOS app using CocoaPods for all dependency management
  2. Added an embedded Cocoa Touch framework (to share code with extensions)

Issue

Some libraries linked through CocoaPods having "duplicated implementation" across both the framework and app. This causes the app to crash when arbitrarily choosing an implementation to use in run-time.

This is apparently a bug within CocoaPods, as most of my dependencies link and run fine - only had issues with a few (Firebase, Fabric, AppsFlyerFramework).


I was proposed a solution to try creating a post install hook to remove the double linking, but I am not sure how best to do approach this.

How can I easily remove dependency links from a specific target through the post install hook? I have seen some post_install hooks like this, but this removes a specific file whereas I need to remove the whole pod link.

post_install do |installer|
    installer.pods_project.targets.each do |target|
        if target.name == 'Pods-Earthlings'
            source_files = target.source_build_phase.files
            dummy = source_files.find do |file|
                file.file_ref.name == 'SomeDuplicate.m'
            end
            source_files.delete dummy
        end
    end
end
0 Answers
Related