从podspec向Xcode项目添加运行脚本构建阶段 [英] Add run script build phase to Xcode project from podspec

查看:967
本文介绍了从podspec向Xcode项目添加运行脚本构建阶段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为我的库编写Cocoapods规范,该规范必须修改Xcode项目并将Run Script Build Phase添加到项目的目标中。我以为我可以使用 post_install 挂钩。
但是 pod spec lint 表示不推荐使用此挂钩:

I'm trying to write Cocoapods specification for my library which must modify Xcode project and add "Run Script Build Phase" to project's target. I thought I can use post_install hook. But "pod spec lint" says that this hook is deprecated:

- WARN  | [iOS] The post install hook of the specification DSL has been deprecated, use the `resource_bundles` or the `prepare_command` attributes.

我不知道如何用* resource_bundles *或* prepare_command *替换post_install hook。
谁知道解决我问题的其他方法?是否可能?

I have no idea how I can replace post_install hook with *resource_bundles* or *prepare_command*. Who knows any other approach to solve my problem? Is it possible?

另一个问题是如何修改Xcode项目以添加构建阶段,但只有在解决了post_hook problem时它才是实际的。

And another problem is how to modify Xcode project to add build phase, but it is actual only when "post_hook problem" is solved.

推荐答案

使用Xcodeproj ruby​​ gem(它是Cocoapods的一部分)编写一个修改Xcode项目的脚本。

Use the Xcodeproj ruby gem (which is part of Cocoapods) to write a script that modifies your Xcode project.

然后使用 prepare_command 调用此脚本。

require 'xcodeproj'
path_to_project = "${SOURCE_ROOT}/${PROJECT_NAME}.xcodeproj"
project = Xcodeproj::Project.open(path_to_project)
main_target = project.targets.first
phase = main_target.new_shell_script_build_phase("Name of your Phase")
phase.shell_script = "do sth with ${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/your.file"
project.save()

文档: http://rubydoc.info/gems/xcodeproj/frames

您可以通过运行来获取构建设置变量及其值的列表...

You can get a list of build setting variables and their values by running…

xcodebuild -project [ProjectName].xcodeproj -target "[TargetName]" -showBuildSettings

更新:
自从写完这个答案后,有些事情发生了变化。目前正在讨论访问环境变量的问题: https://github.com/CocoaPods/CocoaPods / issues / 2115

这篇关于从podspec向Xcode项目添加运行脚本构建阶段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆