自动增加内部版本号 xcode?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12369998/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 01:27:30  来源:igfitidea点击:

Auto increment build number xcode?

iphonexcode

提问by ourmanflint

I am trying to implement the answer here:

我正在尝试在这里实施答案:

Better way of incrementing build number?

增加内部版本号的更好方法?

but cannot get it to work properly. It fails with error 2 saying "No build number in plist"

但无法让它正常工作。它失败,错误 2 说“plist 中没有内部版本号”

But if I put a build number in my plist, the script clears it on the next build, then the same thing happens all over again.

但是如果我在我的 plist 中放入一个内部版本号,脚本会在下一个版本中清除它,然后同样的事情再次发生。

Any ideas?

有任何想法吗?

回答by FluffulousChimp

Here's how I increment build numbers:

这是我增加内部版本号的方法:

In the Target > Summary tab, set the initial build # enter image description here

在 Target > Summary 选项卡中,设置初始构建 # 在此处输入图片说明

Then use this script to increment the build number:

然后使用此脚本增加内部版本号:

#!/bin/bash
buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$INFOPLIST_FILE")
buildNumber=$(($buildNumber + 1))
buildNumber=$(printf "%04d" $buildNumber)
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "$INFOPLIST_FILE"

or if you want build numbers in hex:

或者,如果您想以十六进制构建数字:

#!/bin/bash
buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$INFOPLIST_FILE")
buildNumber=$((0x$buildNumber))
buildNumber=$(($buildNumber + 1))
buildNumber=$(printf "%04X" $buildNumber)
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "$INFOPLIST_FILE"

回答by Fabiano Francesconi

My solution is the following:

我的解决方案如下:

#!/bin/bash
buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$INFOPLIST_FILE")
buildNumber=$(echo $buildNumber | sed 's/0*//')
buildNumber=$(($buildNumber + 1))
buildNumber=$(printf "%04d" $buildNumber)
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "$INFOPLIST_FILE"

Using sed to remove leading zeroes, incrementing the value and printing it back in the plist file using a four-digit-zero-padded number.

使用 sed 删除前导零,增加值并使用四位零填充数字将其打印回 plist 文件。

回答by Rivera

And if you use Jenkins you can use the Jenkins build number

如果您使用 Jenkins,您可以使用 Jenkins 内部版本号

/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $BUILD_NUMBER" "$INFOPLIST_FILE";