在启用资产库的情况下在 Xcode 5 中修改 Info.plist 的 CFBundleVersion
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19164939/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Modifying Info.plist's CFBundleVersion in Xcode 5 with Asset Library enabled
提问by SpacePyro
With Xcode 5's new Asset Library, adding images and organizing them has never been easier. However, it seems as if it has broken some scripts I use for creating builds.
使用 Xcode 5 的新资源库,添加图像和组织它们从未如此简单。但是,它似乎破坏了我用于创建构建的一些脚本。
I have a script within my Run Script Phase that sets the CFBundleVersion
to be the current timestamp within the plist. In the script, I execute this statement:
我的运行脚本阶段中有一个脚本,它将CFBundleVersion
plist设置为当前时间戳。在脚本中,我执行以下语句:
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $timestamp" $BUILT_PRODUCTS_DIR/$INFOPLIST_PATH
However, when this gets executed, the following statement displays:
但是,执行此操作时,将显示以下语句:
Set: Entry, ":CFBundleVersion", Does Not Exist
File Doesn't Exist, Will Create: /Users/SpacePyro/Library/DerivedData/BundleTest-duikdqngfmrovnagrcsvdcuxxstz/Build/Products/Debug-iphoneos/BundleTest.app/Info.plist
It seems like this happens on clean builds. The plist doesn't seem to get generated until midway through the build, presumably due to the Asset Libraries.
这似乎发生在干净的构建中。plist 似乎直到构建中途才生成,大概是由于资产库。
I've also used this command, and while it doesn't throw the error, it still blows away my changes (assume INFO_PLIST="${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/Info"
):
我也使用过这个命令,虽然它没有抛出错误,但它仍然会破坏我的更改(假设INFO_PLIST="${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/Info"
):
defaults write $INFO_PLIST CFBundleVersion $timestamp
This used to not be the case when I started using the Asset Library to organize my app icons and splash images. Anyone know why this happens? And better yet, is there a workaround to add this value to the plist? I've already tried placing the script in a pre-action build phase, as well as the post-action build phase. I've also tried running the command after the build has completed, but when I try to codesign and package it up, it says that the signature is invalid due to plist modification.
当我开始使用资产库来组织我的应用程序图标和启动图像时,情况并非如此。有谁知道为什么会这样?更好的是,是否有解决方法可以将此值添加到 plist 中?我已经尝试将脚本置于操作前构建阶段以及操作后构建阶段。我也尝试在构建完成后运行该命令,但是当我尝试对其进行编码和打包时,它说由于 plist 修改,签名无效。
If no reasonable solution exists, I guess I could always de-migrate from Asset Libraries until I can get my scripts to work.
如果不存在合理的解决方案,我想我总是可以从资产库中取消迁移,直到我可以让我的脚本工作。
采纳答案by SpacePyro
Figured this one out, and it was a silly one. Turns out you can just move the script phase to the very end. I didn't even know these were movable, or that it mattered! But by dragging the Run Script phase to the bottom as such, the scripts were able to run and modify things as needed.
想通了这一点,这是一个愚蠢的。事实证明,您可以将脚本阶段移动到最后。我什至不知道这些是可移动的,或者这很重要!但是通过将运行脚本阶段拖到底部,脚本能够根据需要运行和修改内容。
回答by Code Farmer
I had similar issue once, and here is what finally helped me out:
我曾经遇到过类似的问题,以下是最终帮助我解决的问题:
buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${INFOPLIST_FILE}")
buildNumber=$(($buildNumber + 1))
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "${INFOPLIST_FILE}"
(Use INFOPLIST_FILEdirectly, not $BUILT_PRODUCTS_DIR/$INFOPLIST_PATH)
(直接使用INFOPLIST_FILE,而不是$BUILT_PRODUCTS_DIR/$INFOPLIST_PATH)
Hope this could be useful .
希望这可能有用。
回答by Fabian Guerra Soto
I had the same problem, In my case, I had a wrong file path to the XXX-Info.plist file:
我遇到了同样的问题,就我而言,XXX-Info.plist 文件的文件路径错误:
Build Settings -> Packaging -> Info.plist File
构建设置 -> 打包 -> Info.plist 文件
I changed it it's actual location and start working.
我改变了它的实际位置并开始工作。
回答by Manabu Nakazawa
If your plist file is Preprocessed-Info.plist
, then change the value of "Preprocess Info.plist File" (INFOPLIST_PREPROCESS
) to "Yes" (true
) like this:
如果您的 plist 文件是Preprocessed-Info.plist
,则将“Preprocess Info.plist File”(INFOPLIST_PREPROCESS
)的值更改为“Yes”(true
),如下所示: