美文网首页IOS 拾遗
Cocoapods 为 xcconfig 添加额外的参数

Cocoapods 为 xcconfig 添加额外的参数

作者: madaoCN | 来源:发表于2021-12-15 19:21 被阅读0次

    有时候我们需要重新设置 Pods-xxx.xcconfigOTHER_LDFLAGS 标志

    可以使用如下脚本

    # update xcconfig property
    def update_xcconfig(xcconfig_path, key, value)
        # read from xcconfig to build_settings dictionary
        build_settings = Hash[*File.read(xcconfig_path).lines.map{|x| x.delete!("\n").split(/\s*=\s*/, 2)}.flatten]
    
        # modify key
        if build_settings.has_key?(key)
            build_settings[key] << value
        else
            build_settings[key] = value
        end
    
        # write build_settings dictionary to xcconfig
        File.open(xcconfig_path, "w+") {|file|
           build_settings.each do |k, v|
             file.puts "#{k} = #{v}"
           end
        }
    end
    
    # post_install hook
    post_install do |installer|
        installer.pods_project.targets.each do |target|
            target.build_configurations.each do |config|
                # 添加额外的 OTHER_LDFLAGS
                xcconfig_path = config.base_configuration_reference.real_path
                update_xcconfig(xcconfig_path, 'OTHER_LDFLAGS', ' -ObjC')
            end
        end
    end
    

    非常的简单实用,

    参考 How can I modify OTHER_LDFLAGS via CocoaPods post-install hook?

    相关文章

      网友评论

        本文标题:Cocoapods 为 xcconfig 添加额外的参数

        本文链接:https://www.haomeiwen.com/subject/bkvpfrtx.html