将运行脚本构build阶段添加到来自podspec的Xcode项目中
我正在为我的库编写Cocoapods规范,它必须修改Xcode项目,并将“运行脚本构build阶段”添加到项目的目标。 我以为我可以使用post_install挂钩。 但是“ pod spec lint ”说这个钩子已经被弃用了:
- 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 *replacepost_install钩子。 谁知道解决我的问题的其他方法? 可能吗?
而另一个问题是如何修改Xcode项目来添加构build阶段,但只有解决了“post_hook问题”时才是实际的。
使用Xcodeproj ruby gem(它是Cocoapods的一部分)来编写一个修改你的Xcode项目的脚本。
然后使用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
您可以通过运行来获取构build设置variables及其值的列表…
xcodebuild -project [ProjectName].xcodeproj -target "[TargetName]" -showBuildSettings
更新:自从写这个答案以来,有些事情已经改变了。 访问环境variables的问题目前正在讨论中: https : //github.com/CocoaPods/CocoaPods/issues/2115