How to set CURRENT_PROJECT_VERSION in Xcode 8
Asked Answered
B

3

18

Since upgrading to Xcode 8, when I do a build with fastlane, I get the following error message:

There does not seem to be a CURRENT_PROJECT_VERSION key set for this project

If I go to Xcode > Build Settings and go down to Versioning, there is a Current Project Version key, as shown below:

screen shot of versioning

The help text says to enter an integer or floating point number, but when I click on the field, there is no opportunity to enter a number in either the Debug or Release field. This is different from the screen shot shown in this apple tech Q&A so there appears to have been a change in Xcode since the Q&A was released.

Brought answered 24/9, 2016 at 6:29 Comment(0)
D
18

Currently when you get that fastlane error, terminal logs redirects you to

Automating Version and Build Numbers Using agvtool

to understand what you need to do.

Summary

  1. Enable agvtool.

    Build Settings > Current Project Version > $(CURRENT_PROJECT_VERSION)

    Build Settings > Versioning System > Apple Generic enter image description here

  2. Set up your version and build numbers.

    Target > Info > Bundle versions string, short (CFBundleShortVersionString) > "your init version"

    Target > Info > Bundle version (CFBundleVersion) > "your init value" enter image description here

That helps me a lot.

Devi answered 24/5, 2017 at 13:59 Comment(1)
Don't do this. Using agvtool writes changes into the CURRENT_PROJECT_VERSION build setting in your project.pbxproj file which will cause merge conflicts. Use this approach instead. https://mcmap.net/q/655017/-how-to-set-current_project_version-in-xcode-8Novena
N
23

Don't. Modify the values in your app's info.plist file instead.

This means not using agvtool (as I learned).

Why? Over the years, Apple has come up with several manners of changing version and build numbers. Many of them are now outdated and poor practice. Changing CURRENT_PROJECT_VERSION modifies values within your project's project.pbxproj file and if you are running a distributed team, this will cause merge conflicts if the other half of the team tries to update and while they were asleep, you updated this internal value. If you are using pods, you'll get several more merge conflicts per pod that you add to the project.

So, CURRENT_PROJECT_VERSION?

Don't use it.

Within the info.plist file are these keys.

CFBundleVersion
CFBundleShortVersionString

Use CFBundleVersion for your app's build number. Use CFBundleShortVersionString for your app's version number.

Use Plistbuddy to do it.

    <key>CFBundleShortVersionString</key>
    <string>3.0.7</string>
    <key>CFBundleVersion</key>
    <string>934</string>
</dict>
</plist>

Try the script below.

#!/bin/sh

# To make executable, use: chmod u+x Build-Versioning-Scripts/Increment_Build_Number.sh
# to locate your target's info.plist use
# ${PRODUCT_SETTINGS_PATH}

echo "----"
echo "Info.plist for target: ${PRODUCT_SETTINGS_PATH}"

buildNum=$(/usr/libexec/Plistbuddy -c "Print CFBundleVersion" "${PRODUCT_SETTINGS_PATH}")
echo "Current build #: $buildNum"

if [ -z "$buildNum" ]; then
echo "No build number found in $PRODUCT_SETTINGS_PATH"
exit 2
fi

buildNum=$(expr $buildNum + 1)
echo "Build # incremented to: $buildNum"
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNum" "$PRODUCT_SETTINGS_PATH"
echo "----"
exit 0

By adding this script to your build or archive process on your build machine, this will automatically update the app's build number. If you wish to increment your app's version number, change CFBundleShortVersionString (Bundle versions string, short) in the info.plist manually.

Novena answered 4/4, 2019 at 21:46 Comment(7)
The question was about fastlane, changing CFBundleShortVersionString manually isn't a solution.Ichthyic
Fastlane uses agvtool. My recommendation (strongly) is not to use this for versioning. Note that my comment stated that updating the app's version number can be manually updated, not the app's build number, which my script does automatically. This script doesn't do it manually. I'll edit my wording to make it more clear. build# ≠ version#Novena
Xcode 11 (re)introduced MARKETING_VERSION and CURRENT_PROJECT_VERSION build settings but agvtool writes version and build numbers directly into Info.plist.Moira
stackoverflow.com/users/1694191/andré-costa-lima, I saw in our project that agvtool also modified our .xcodeproj file in about 10 places every time it was used in both Xcode 10 and Xcode 11. Naturally, this complicated merges. That it also wrote this info into the .xcodeproj file was surprising.Novena
if this modifies the info.plist directly, then how is it kept in sync with the build # in the build settings? or does that not matter?Navaho
@bze12, I forget. I believe that the build number in build settings uses that value in the variable from the plist.Novena
Why is this upvoted so much? 1. The default Xcode project version uses CURRENT_PROJECT_VERSION. 2. When you set the build number in the project view, CURRENT_PROJECT_VERSION is updated. 3. Using CURRENT_PROJECT_VERSION is NOT why conflicts happen. Using the Info.plist can still result in a conflict. If I have to choose between an option Apple built into Xcode and a SO answer, I usually go with the option Apple gave.Kendre
D
18

Currently when you get that fastlane error, terminal logs redirects you to

Automating Version and Build Numbers Using agvtool

to understand what you need to do.

Summary

  1. Enable agvtool.

    Build Settings > Current Project Version > $(CURRENT_PROJECT_VERSION)

    Build Settings > Versioning System > Apple Generic enter image description here

  2. Set up your version and build numbers.

    Target > Info > Bundle versions string, short (CFBundleShortVersionString) > "your init version"

    Target > Info > Bundle version (CFBundleVersion) > "your init value" enter image description here

That helps me a lot.

Devi answered 24/5, 2017 at 13:59 Comment(1)
Don't do this. Using agvtool writes changes into the CURRENT_PROJECT_VERSION build setting in your project.pbxproj file which will cause merge conflicts. Use this approach instead. https://mcmap.net/q/655017/-how-to-set-current_project_version-in-xcode-8Novena
M
-3

you may try change project format ?

I suggest you can change this xcode format version.

Metcalf answered 6/9, 2017 at 5:20 Comment(1)
To what? And why?Novena

© 2022 - 2024 — McMap. All rights reserved.