简体   繁体   English

如何在Xcode项目包中排除图像文件,有条件地发布版本?

[英]How to exclude image files in Xcode project bundle, conditionally for Release version?

I added .png images to the Xcode project for conditional use like making screenshots of a view However, since this is not needed for the Release version of the app, I would like to find a way to exclude them using some kind of settings for Target . 我将.png图像添加到Xcode项目中以进行条件使用,例如制作视图的屏幕截图但是,由于应用程序的发布版本不需要这样,我想找到一种方法来使用Target的某种设置来排除它们 I expect there can be a solution like using #if DEBUG macro for Debug compilation, which can work for lines of source code. 我希望可以有一个解决方案,例如使用#if DEBUG宏进行Debug编译,这可以用于源代码行。 But, in case of files included in project bundle , I am having trouble finding the answers. 但是, 如果项目包中包含文件 ,我很难找到答案。

In Xcode 3, there's a view above the editor that lists the files in the project. 在Xcode 3中,编辑器上方有一个视图,列出了项目中的文件。 There's a checkbox on the right side of that view for each file, and you can uncheck the box to remove the file from the current target. 每个文件的视图右侧都有一个复选框,您可以取消选中该框以从当前目标中删除该文件。

In Xcode 4, show the Project Navigator on the left side of the window, and show the File Inspector on the right side, in the Utilities area. 在Xcode 4中,显示窗口左侧的Project Navigator,并在Utilities区域的右侧显示File Inspector。 When you select a file, you'll see a Target Membership area with a list of targets and checkboxes. 选择文件时,您将看到目标成员资格区域,其中包含目标和复选框列表。 If you want to exclude the file from a particular target, uncheck the box next to that target. 如果要从特定目标中排除文件,请取消选中该目标旁边的框。 Here's a picture: 这是一张图片:

在此输入图像描述

This is a bit different from excluding files from only some builds of a single target. 这与仅从单个目标的某些构建中排除文件略有不同。 Still, I think it's the simplest mechanism to use for the situation that you describe. 不过,我认为这是用于描述情况的最简单的机制。 Simply duplicate your existing target so that you have a copy that you can use for making screenshots. 只需复制现有目标,即可获得可用于制作屏幕截图的副本。 Remove the extra files from your production target but leave them in the screenshot target, as described above. 从生产目标中删除多余的文件,但将其保留在屏幕截图目标中,如上​​所述。

A target's inputs are the same for all builds, so there's no checkbox that will do it for you. 目标的输入对于所有构建都是相同的,因此没有复选框可以为您完成。

All that really happens though is that image files like .png or whatever get added to the copy bundle resources phase. 所有真正发生的事情是,像.png这样的图像文件或其他任何内容都会被添加到复制包资源阶段。 You can remove them from that phase and instead create a custom script build phase using a shell script. 您可以从该阶段中删除它们,而是使用shell脚本创建自定义脚本构建阶段。

It will default to printing out all the environment variables set by xcode, from there you should be able to write a script which only performs the copy when say ${BUILD_STYLE} is 'Debug'. 它将默认打印出xcode设置的所有环境变量,从那里你应该能够编写一个只在执行$ {BUILD_STYLE}是'Debug'时执行复制的脚本。

You probably want ${BUILD_STYLE}, ${CONTENTS_FOLDER_PATH} and ${INPUT_FILE_PATH} for starters. 对于初学者,您可能需要$ {BUILD_STYLE},$ {CONTENTS_FOLDER_PATH}和$ {INPUT_FILE_PATH}。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM