<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Xcode 11 &#8211; Tjitjing Blog</title>
	<atom:link href="http://localhost/index.php/tag/xcode-11/feed" rel="self" type="application/rss+xml" />
	<link>https://blog.tjitjing.com/</link>
	<description>This is my blog on technology related stuff and on occation other things too...</description>
	<lastBuildDate>Tue, 14 Sep 2021 07:29:00 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.1.16</generator>
	<item>
		<title>Auto-increment build number in Xcode 11 / Xcode 12</title>
		<link>https://blog.tjitjing.com/index.php/2021/09/auto-increment-build-number-in-xcode-11-xcode-12.html</link>
					<comments>https://blog.tjitjing.com/index.php/2021/09/auto-increment-build-number-in-xcode-11-xcode-12.html#comments</comments>
		
		<dc:creator><![CDATA[Max]]></dc:creator>
		<pubDate>Tue, 14 Sep 2021 06:12:09 +0000</pubDate>
				<category><![CDATA[App Development]]></category>
		<category><![CDATA[Apple]]></category>
		<category><![CDATA[Xcode]]></category>
		<category><![CDATA[avgtool]]></category>
		<category><![CDATA[CFBundleVersion]]></category>
		<category><![CDATA[Info.plist]]></category>
		<category><![CDATA[pbxproj]]></category>
		<category><![CDATA[Xcode 11]]></category>
		<category><![CDATA[Xcode 12]]></category>
		<guid isPermaLink="false">https://blog.tjitjing.com/?p=818</guid>

					<description><![CDATA[Xcode 11 moved version handling to the .pbxproj file, in addition to Info.plist, which broke my script to automatically increase build number on each build. Solution for Xcode 11/12 is shown below. Background &#8211; pre Xcode 11 / Xcode 12 Before Xcode 11 the &#8220;normal&#8221; way to auto increment build number was to read current&#8230; <a class="more-link" href="https://blog.tjitjing.com/index.php/2021/09/auto-increment-build-number-in-xcode-11-xcode-12.html">Continue reading <span class="screen-reader-text">Auto-increment build number in Xcode 11 / Xcode 12</span></a>]]></description>
										<content:encoded><![CDATA[
<p><strong>Xcode 11 moved version handling to the .pbxproj file, in addition to Info.plist, which broke my script to automatically increase build number on each build. Solution for Xcode 11/12 is shown below.</strong></p>



<h2>Background &#8211; pre Xcode 11 / Xcode 12</h2>



<p>Before Xcode 11 the &#8220;normal&#8221; way to auto increment build number was to read current build number from <strong>Info.plist</strong> using the MacOS PlistBuddy tool and then increment that number and write the updated build number back to Info.plist, again using PlistBuddy. Or you could use avgtool or some 3rd party solution.</p>



<p>However, with Xcode11 (and currently Xcode12) version number and buildnumber are set in the <strong>pbxproj</strong> file, and Info.plist only reference what is set in pbxproj.</p>



<p>This change got my old script to generate an error on build: <strong>Command PhaseScriptExecution failed with a nonzero exit code</strong></p>



<pre class="wp-block-preformatted">$(CURRENT_PROJECT_VERSION) + 1: syntax error: operand expected (error token is "$(CURRENT_PROJECT_VERSION) + 1")<br>Command PhaseScriptExecution failed with a nonzero exit code</pre>



<p>This is what Info.plist now looks like in Xcode11 / Xcode12, i.e. there is no longer an actual build number to read from Info.plist, only a reference to what is set in the pbxproj file.</p>



<pre class="wp-block-preformatted">&lt;key&gt;CFBundleShortVersionString&lt;/key&gt; 
&lt;string&gt;$(MARKETING_VERSION)&lt;/string&gt; 

&lt;key&gt;CFBundleVersion&lt;/key&gt;
&lt;string&gt;$(CURRENT_PROJECT_VERSION)&lt;/string&gt;</pre>



<h2>Solution for Xcode 11 / Xcode 12</h2>



<p>So, in Xcode 11/12 we now need to update the pbxproj file instead of Info.plist.</p>



<p><strong>Use this script to auto increment build number:</strong></p>



<pre class="wp-block-preformatted">buildNumber=$(xcodebuild -showBuildSettings | grep CURRENT_PROJECT_VERSION | tr -d 'CURRENT_PROJECT_VERSION =')
buildNumber=`echo $buildNumber +1|bc`
xcrun agvtool new-version $buildNumber</pre>



<p><strong>To add the script in Xcode 12, follow these steps:</strong></p>



<ol><li>Select your Project Target (Target, not Project)</li><li>Select Build Phases</li><li>Add a new Build Phase by clicking the plus (+) icon on top left</li><li>If you wish you can rename the new Build phase, e.g. Set Build Number</li><li>Copy the script above and paste it</li><li>You can leave all other Build Phase settings as default</li><li>Done &#8211; Build your project and watch build number increment with 1 for each build</li></ol>



<p>This was latest tested on Xcode 12.5 and macOS Big Sur 11.5.2 on a MacBook Air M1</p>



<h2>Did this solution help you?</h2>



<p>I hope this helped! <strong>Please comment</strong> if it did, or if you had any problem with it. Also let me know if you got it working (or not) using other versions or if you found a better solution – <strong>it will help me and others!</strong></p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.tjitjing.com/index.php/2021/09/auto-increment-build-number-in-xcode-11-xcode-12.html/feed</wfw:commentRss>
			<slash:comments>6</slash:comments>
		
		
			</item>
	</channel>
</rss>
