Skip to content

Instantly share code, notes, and snippets.

@tomredman
Last active March 23, 2019 03:27
Show Gist options
  • Save tomredman/9769940 to your computer and use it in GitHub Desktop.
Save tomredman/9769940 to your computer and use it in GitHub Desktop.
Add file to specific Pods' Frameworks Build Phase using cocoapods' post_install

In a large, nested project where I prefer to control the workspace, I run pod install --no-integrate on my root project. However, some pods don't include their required static libs correctly within their target's framework build phases.

For example, Pod-TestFlightSDK's required libTestFlight.a is excluded and removed every time I update my pods. Which required me to manually update the Pod target each time to include the static lib, which required me to automate it:

post_install do |installer_representation|
    installer_representation.project.targets.each do |target|
        if target.name == 'Pods-TestFlightSDK'
            libFile = installer_representation.project.new_file('TestFlightSDK/libTestFlight.a')
        end
        
        if target.name == 'Pods-Brightcove-Player-SDK'
            libFile = installer_representation.project.new_file('Brightcove-Player-SDK/Library/libBCOVPlayerSDK.a')
        end
        
        unless libFile.nil?
            puts "     - Adding %s to %s Frameworks Build Phases" % [libFile, target.name]
            target.frameworks_build_phase.add_file_reference(libFile)
        end
    end
end
@rishijoshi-ibm
Copy link

Hi @tomredman, how do I add a .framework to Framework Build Phase?
I tried using your method, but Framework is showing up without the usual Yellow briefcase icon. FYI, the Framework is also a part of the Podfile and is a static framework. I have a dynamic framework which needs this status framework to be linked. I can do that manually but want to automate by writing it inside Podfile as a post_install hook.

@shawnthye
Copy link

Hi @tomredman, how do I add a .framework to Framework Build Phase?
I tried using your method, but Framework is showing up without the usual Yellow briefcase icon. FYI, the Framework is also a part of the Podfile and is a static framework. I have a dynamic framework which needs this status framework to be linked. I can do that manually but want to automate by writing it inside Podfile as a post_install hook.

Hi! try this.

use target.add_system_framework(installer.pods_project.targets.find{|target| target.name == 'YouFrameworkName'})

@jaysonjh
Copy link

I use target.add_system_framework(installer.pods_project.targets.find{|target| target.name == 'YouFrameworkName'}) in my pod, but can't run success.

An error occurred while processing the post-install hook of the Podfile.
undefined local variable or method `frameworks_build_phase' for #Xcodeproj::Project::Object::PBXAggregateTarget:0x007fd7fb488d68
Did you mean? frameworks_build_phases

@jaysonjh
Copy link

I already fixed this. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment