How to set CURRENT_PROJECT_VERSION in xcode 8

2019-04-10 16:34发布

问题:

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:

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.

回答1:

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

  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"

That helps me a lot.



回答2:

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

If you wish to increment your app's version number, change CFBundleShortVersionString (Bundle versions string, short) in the info.plist manually.



回答3:

you may try change project format ?

I suggest you can change this xcode format version.



标签: xcode8