user1107173
user1107173

Reputation: 10744

Xcode: Increment build number

We use a script that creates a time stamp and replaces the apps build number.

#!/bin/bash
echo "Update Build Number to Timestamp"
echo "--------------------------------"
# fail on error
set -e
agvtool new-version -all $(date +%Y%m%d%H%M%S)

This changes the build number to something like this: 201703241425.

We introduced an in-house framework to our Project.

The command above also replaces the frameworks Build number and Current Library Version. However, the builds fail with the following error:

▸ Linking In-HouseFrameworkLayer

❌  ld: malformed 64-bit a.b.c.d.e version number: 201703241425
❌  clang: error: linker command failed with exit code 1 (use -v to see invocation)

enter image description here

When I change the format for the framework's Build number, Current Library Version to 1.0.0 and do a build without using the script above, the builds are successful.

Question: How can I change the Build number ONLY for the app, but NOT the framework Current Library Version number?

Upvotes: 2

Views: 7223

Answers (3)

Irfan Anwar
Irfan Anwar

Reputation: 1918

If you want to keep $(MARKETING_VERSION) in Info.plist for CFBundleShortVersionString but want to increase version after successful archive or build then use following script following script will increase app version like 1.0 to 2.0 but of-course that logic can be modified to lets say, add 1 more decimal to app version, or even increase minor or tiny/patch or major part of decimal, or even you can increase both version and build numbers, but you have to do that learning from other easily available scripts and modify accordingly

Script to increase app version

Upvotes: 0

Debashish Das
Debashish Das

Reputation: 919

Let's do this in Apple's own way. It will increase the build number after each successful build

I will guide you through 5 images, just go through it.

  1. Select 'Edit Scheme...' from the dropdown, when you select your Project name located in right side to the Stop_build_button. Check First Step

  2. From leftSide menu expand the 'Build' option and select 'Post-actions' Check Second Step

  3. Here you can add your desired Codes(Scripts) you want to execute after successful build of your program. It is the place where we have to add a little amount of code to make our automation work perfectly. >> 1. select the 'add (+)' button from leftSide corner to add new script file >> 2. Now from the drop down select 'New Run Script Action' Check Third Step

  4. It has 3 fields >> 1. shell is already assigned for you >> 2. now for 'Provide you build settings from' Select your Project Name. >> 3. Theres a big field to add your Script, just copy and past this code there : Check Fourth Step

    PLIST="${PROJECT_DIR}/${INFOPLIST_FILE}" PLB=/usr/libexec/PlistBuddy LAST_NUMBER=$($PLB -c "Print CFBundleVersion" "$PLIST") NEW_VERSION=$(($LAST_NUMBER + 1)) $PLB -c "Set :CFBundleVersion $NEW_VERSION" "$PLIST"

  5. After completing the 4th step just select 'Close' to close the window and we have to do the last step, Goto your 'plist.info' file in Project file menu and make sure 'Bundle Version' key under 'Key' Section most contain a Numeric Value Check Fifth Step

Upvotes: 3

l'L'l
l'L'l

Reputation: 47159

Obviously the app uses CFBundleVersion + $(CURRENT_PROJECT_VERSION); libraries/frameworks are supposed to use (Current Library Version) + $(DYLIB_CURRENT_VERSION)

By default it is set to $(CURRENT_PROJECT_VERSION), so this is what you'll need to change to the $(DYLIB_CURRENT_VERSION) string.

Important: For macOS apps, build numbers must monotonically increase even across different versions. In other words, for macOS apps you cannot use the same build numbers again in different release trains. iOS apps have no such restriction and you can re-use the same build numbers again in different release trains.

The value for a version number or build number must consist only of '.'s and numbers and must begin and end with a number. Each integer value separated by a period is a component of the version. The maximum number of characters in your version number or in your build number cannot exceed eighteen characters in total.

iOS version numbers and build numbers may have three or more components, but the maximum size of the entire version number or build number must not exceed eighteen characters.

macOS apps are somewhat more restrictive than iOS apps. For macOS apps there is a limit of three components separated by periods and there may not be any more than three components.

Version Numbers and Build Numbers

Automating Version and Build Numbers Using agvtool

Upvotes: 3

Related Questions