Search code examples
cocoapodsxcodeproj

Hook in Podfile to edit my project file


I want to fix Cocoapods bug, when it adds Embed Pods Frameworks build phase for Extension targets. These phases are not needed there.

https://github.com/CocoaPods/CocoaPods/issues/4203

I wrote script to remove it

puts "Deleting not needed phases…"
project_path = "Keyboard.xcodeproj"
project = Xcodeproj::Project.open(project_path)
project.targets.each do |target|
    if target.name.include?("Extension")
        phase = target.shell_script_build_phases.find { |bp| bp.name == 'Embed Pods Frameworks' }
        if !phase.nil?
            puts "Deleting Embed Pods Frameworks phase…"
            target.build_phases.delete(phase)
        end
    end
end

project.save

I can run this script after pod install manually, but I want to add it to Podfile somehow. It doesn't work in post_install hook

post_install do |installer|
    ...
end

because UserProjectIntegrator.integrate! is called after post_install and it overrides my changes.

Is there any way to integrate this script in Podfile?


Solution

  • The short answer is No.
    The long answer:
    From the output of pod install --verbose, the build phase Embed Pods Frameworks is added in the Integrating client project which runs after the post_install step in the Podfile. This is why you should execute this script separately after the pod install finished running.