ios - 如何在 Xcode 4 中自动增加捆绑版本?

我试图弄清楚如何在我的 Xcode 4 项目中自动增加 Bundle 版本号(用于临时和发布版本)。我在网上找到了一些声称可以执行此操作的脚本,但我不确定是将它们放在“前置操作”还是“后置操作”中。我也不确定我应该在 plist 中放置什么值;然后脚本将更改的数字或变量?

到目前为止,我尝试过的所有选项似乎都不起作用,因此我们将不胜感激。

以下是我尝试使用的最新脚本:

conf=${CONFIGURATION}
arch=${ARCHS:0:4}
# Only increase the build number on Device and AdHoc/AppStore build
if [ $conf != "Debug" ] && [ $conf != "Release" ] && [ $arch != "i386" ]
then
buildPlist=${INFOPLIST_FILE}
buildVersion=$(/usr/libexec/PlistBuddy -c "Print CFBuildVersion" $buildPlist)
buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBuildNumber" $buildPlist)
buildNumber=$(($buildNumber + 1))
/usr/libexec/PlistBuddy -c "Set :CFBuildNumber $buildNumber" $buildPlist
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildVersion.$buildNumber" $buildPlist
/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $buildVersion.$buildNumber" $buildPlist
fi

最佳答案

1,将 CFBundleVersion 设置为 1.0.1 或类似 x.x.x

2、添加构建阶段以运行shell脚本autoVersion.sh

3、保存下面名为autoVersion.sh的脚本

#!/bin/sh
# Auto Increment Version Script
# set CFBundleVersion to 1.0.1 first!!!
# the perl regex splits out the last part of a build number (ie: 1.1.1) and increments it by one
# if you have a build number that is more than 3 components, add a '\.\d+' into the first part of the regex.
buildPlist=${INFOPLIST_FILE}
newVersion=`/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$buildPlist" | /usr/bin/perl -pe 's/(\d+\.\d+\.)(\d+)/$1.($2+1)/eg'`
#echo $newVersion;
/usr/libexec/PListBuddy -c "Set :CFBundleVersion $newVersion" "$buildPlist"

4、运行shell:cp autoVersion.sh ~/Documents/and chmod 777 ~/Documents/autoVersion.sh

5,构建并享受它。 :)

perl 代码来自:https://gist.github.com/1436598

https://stackoverflow.com/questions/6286937/

相关文章:

java - 错误 :Could not initialize class com. android

build - Gradle 全局构建目录

xcode - 了解 Xcode 的 Copy Headers 阶段

gradle - 如何更改 gradle 插件存储库?

tfs - Cruise Control .Net 与 Team Foundation 构建

gcc - g++ 输出 : file not recognized: File format no

c# - NuGet 以代码 -1 退出 - 结果构建失败

c++ - #error 请为 _AFXDLL 构建使用/MD 开关

c# - 如何获得本地 Visual Studio 构建完成的通知?

command-line - 如何从命令行构建 IntelliJ 项目?