Add run script build phase to Xcode project from podspec

自古美人都是妖i 提交于 2019-11-30 01:39:58

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

You then call this script using the 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()

Documentation: 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

UPDATE: A few things have changed since this answer was written. The issue of accessing environment variables is currently being discussed here: https://github.com/CocoaPods/CocoaPods/issues/2115

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!