2

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?

user1107173
  • 10,334
  • 16
  • 72
  • 117

3 Answers3

3

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

l'L'l
  • 44,951
  • 10
  • 95
  • 146
  • 1
    Thank you for your detailed answer. Inside the framework build settings, I do not see a key for `DYLIB_CURRENT_VERSION`. Am I looking in the right place? – user1107173 Mar 24 '17 at 23:31
  • When I search the project, it shows up. When I tap on it, it appears as `Current Library Version`, and the value is `20170324162615`. – user1107173 Mar 24 '17 at 23:34
  • I am sorry, but I don't have a key for `CFBundleVersion`. All and Combined are selected. – user1107173 Mar 24 '17 at 23:36
  • In the plist for my framework, I do see `Bundle version` and there it says `1.0`. When I run the command `agvtool new-version -all $(date +%Y%m%d%H%M%S)` it changed to `20170324164011`. Also, I do not have a `$(DYLIB_CURRENT_VERSION)` in project. – user1107173 Mar 24 '17 at 23:41
  • Is there a way to change `DYLIB_CURRENT_VERSION` with agvtools? – user1107173 Mar 24 '17 at 23:46
  • When I run the following command: `agvtool new-version -all $(date +%Y%m%d%H%M%S` all the versions are changed to this format: `20170324164011` – user1107173 Mar 24 '17 at 23:51
  • It's `Current Library Version` and `Current Project Version` – user1107173 Mar 24 '17 at 23:56
  • I would like to timestamp the build number -- not sure how else to do it. – user1107173 Mar 24 '17 at 23:57
  • Yes, but what is the actual `` in the XML .plist? – l'L'l Mar 24 '17 at 23:57
  • It's `CFBundleVersion` – user1107173 Mar 24 '17 at 23:58
  • 1
    Yep, as I thought, so you will want to set the `$(DYLIB_CURRENT_VERSION)` for that in the settings, and then have your date or whichever string go to that variable. (eg. `DYLIB_CURRENT_VERSION = 20170324164011`). – l'L'l Mar 25 '17 at 00:00
  • How do I change that with with a script? agvtools? – user1107173 Mar 25 '17 at 00:01
  • Sorry, also where do I add `DYLIB_CURRENT_VERSION = 20170324164011`? in the Framework plist? or Build Settings? – user1107173 Mar 25 '17 at 00:04
  • @user1107173: There are multiple ways you can do it. One easy way is by adding it in your Frameworks `Build Settings` under`Linking` (eg. Setting: `Current Library Version` Value: `20170324164011`). – l'L'l Mar 27 '17 at 18:34
  • That's what the script does, but I get an error: `ld: malformed 64-bit a.b.c.d.e version number: 201703241425` – user1107173 Mar 27 '17 at 18:39
  • What is the actual version number? – l'L'l Mar 27 '17 at 18:40
  • I have two options when I type `version number` under Build Settings of my framework. `Compatibility Version` is set to `1`. The other is `Current Library Version` which is set to `201703241425` – user1107173 Mar 27 '17 at 18:41
3

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

Debashish Das
  • 859
  • 4
  • 14
0

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

Irfan Anwar
  • 1,878
  • 17
  • 30