在pod文件中以编程方式将静态库添加到pod目标(链接的框架和库)

时间:2019-09-06 16:09:43

标签: ruby xcode cocoapods

我想自动将静态库文件(.a)添加到xoce中 这个过程很容易手工完成:

https://www.youtube.com/watch?v=mbE3oku744c&feature=youtu.be

我认为最好的方法是在pod文件中。

但是我不知道如何详细处理。

post_install do |installer|

    installer.pods_project.targets.each do |target|

        if target.name == 'Pods-EVORecording-EVORecording-Movesense'

        # here I think could be the code for adding the .a file

        end
     end
end

将获得解决该任务的一些提示。非常感谢。

1 个答案:

答案 0 :(得分:0)

我自己解决了这个问题。解决方法如下:

post_install do |installer|

  lib_name = "libmds.a"
  lib_path = "Movesense/IOS/Movesense/Release-iphoneos"

  # get ref of lib file
  path = File.dirname(__FILE__) + "/Pods/" + lib_path + "/" + lib_name
  movesense_ref = installer.pods_project.reference_for_path(path)

  installer.pods_project.targets.each do |target|
    # find the right target
    if target.name == 'EVORecording-iOS'
      # add libmds.a file to build files
      build_phase = target.frameworks_build_phase
      build_phase.add_file_reference(movesense_ref)

      target.build_configurations.each do |config|
        # add library search paths
        config.build_settings['LIBRARY_SEARCH_PATHS'] = ["$(inherited)", "$(PROJECT_DIR)/" + lib_path]

      end
    end
  end
end