有时候我们需要重新设置 Pods-xxx.xcconfig
的 OTHER_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?
网友评论