Cocoapods 为 xcconfig 添加额外的参数

有时候我们需要重新设置 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?

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容