0

问题是:CocoaPodsxcconfig为我的项目生成文件,我想将我的xcconfig文件作为依赖项包含在其中。例如,我可以在post_install钩子中做吗?我只发现 XCBuildConfiguration 有build_settings散列,但据我了解,我只能添加或更改键,而不包括带有该散列的语句。

4

1 回答 1

0

按照这个答案的说明,我能够更新xcconfig并使用此代码将我的xcconfig文件包含到生成的 pod 中:

    post_install do |installer|
      installer.pods_project.targets.each do |target|
        next unless target.name.include?("Pods-CNISDK")
        puts "Updating #{target.name}"
        target.build_configurations.each do |config|
          xcconfig_path = config.base_configuration_reference.real_path
          # read from xcconfig to build_settings dictionary
          build_settings = Hash[*File.read(xcconfig_path).lines.map{|x| x.split(/\s*=\s*/, 2)}.flatten]
          # write build_settings dictionary to xcconfig
          File.open(xcconfig_path, "w") do |file|
            file.puts "#include \"../configurations/Warnings.xcconfig\"\n"
            build_settings.each do |key,value|
              file.puts "#{key} = #{value}"
            end
          end
        end
      end
    end
于 2016-09-02T08:50:35.030 回答