Note that there are some explanatory texts on larger screens.

plurals
  1. POBetter way of incrementing build number?
    primarykey
    data
    text
    <p>I have been using a shell script as part of my Xcode build process to increment the build number within the <em>plist</em> file, however it's making Xcode 4.2.1 crash frequently (with an error about the target not belonging to a project; I'm guessing the changing of the <em>plist</em> file is confusing Xcode in some way).</p> <p>The shell script did this so that the build number is only incremented by <code>agvtool</code> when a file is newer than the <em>plist</em> file (so just building didn't increment the value):</p> <pre><code>if [ -n \"`find ProjDir -newer ProjDir/Project-Info.plist`\" ]; then agvtool -noscm next-version -all; else echo \"Version not incremented\"; fi </code></pre> <p>Is there a way to increment the build number (in the <em>plist</em> file, or anywhere else) that doesn't break Xcode?</p> <p><strong>EDIT</strong>: Here is my final solution, based on the suggestion of @Monolo. I created the following script in <code>${PROJECT_DIR}/tools</code> (sibling to the <code>.xcodeproj</code> directory):</p> <pre><code>#!/bin/sh if [ $# -ne 1 ]; then echo usage: $0 plist-file exit 1 fi plist="$1" dir="$(dirname "$plist")" # Only increment the build number if source files have changed if [ -n "$(find "$dir" \! -path "*xcuserdata*" \! -path "*.git" -newer "$plist")" ]; then buildnum=$(/usr/libexec/Plistbuddy -c "Print CFBundleVersion" "$plist") if [ -z "$buildnum" ]; then echo "No build number in $plist" exit 2 fi buildnum=$(expr $buildnum + 1) /usr/libexec/Plistbuddy -c "Set CFBundleVersion $buildnum" "$plist" echo "Incremented build number to $buildnum" else echo "Not incrementing build number as source files have not changed" fi </code></pre> <p><strong>EDIT 2</strong>: I have modified the script to incorporate @Milliways suggestion.</p> <p>I then invoked the script from Xcode target 'Build Phases' section: <img src="https://i.stack.imgur.com/Q2j7c.png" alt="Xcode build phases screenshot"></p> <p><strong>EDIT 3</strong>: As per @massimobio's answer, you'll need to add quotes around the plist argument if it contains spaces.</p> <p><strong>EDIT 4</strong>: Just to update that my preferred method of invoking this build script is now to create a separate target and make the app target dependant upon this <em>Bump Build Number</em> target. This ensures that it is invoked before the app target does <em>anything</em> with the plist (I've noticed that it likes to process the plist at the start of the build). I've also switched to a purely python-based solution that keeps the version number in a separate file, and writes version source files, as this is more useful for cross-platform products (i.e. Visual Studio under Windows can invoke the script, and obviously cmake/make-type builds can do so also). This has the benefit that the build number is always the same even under different platforms, and it's also possible to update the Visual Studio <code>Resource.rc</code> file with the current version/build as well.</p> <p><a href="https://stackoverflow.com/a/36007955/299924">Here</a> is the python script I currently use to update <code>Info.plist</code> files within Xcode project.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload