Xcode-Increment build number only during ARCHIVE?

后端 未结 3 1354
醉梦人生
醉梦人生 2020-12-12 12:01

I have found a few other posts that show how to add a script to increment the build number with a script:

Better way of incrementing build number?

Xcode proj

相关标签:
3条回答
  • 2020-12-12 12:34

    Xcode includes the command line tool agvtool to increase version numbers. So you don't have to do everything manually with PListBuddy.

    xcrun agvtool next-version -all

    increases your build number.

    xcrun agvtool new-marketing-version 2.0

    sets a new user visible version number.

    See the full documentation for details.

    0 讨论(0)
  • 2020-12-12 12:38

    Add the following script, as in the example listed in the first link that you posted, BUT do it twice. Once at the beginning of the build and once at the end:

    if [ $CONFIGURATION == Release ]; then
        echo "Bumping build number..."
        plist=${PROJECT_DIR}/${INFOPLIST_FILE}
    
    # increment the build number (ie 115 to 116)
        buildnum=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${plist}")
        if [[ "${buildnum}" == "" ]]; then
            echo "No build number in $plist"
            exit 2
        fi
    
        buildnum=$(expr $buildnum + 1)
        /usr/libexec/Plistbuddy -c "Set CFBundleVersion $buildnum" "${plist}"
        echo "Bumped build number to $buildnum"
    
    else
        echo $CONFIGURATION " build - Not bumping build number."
    fi
    

    Many thanks to the authors of the questions that you have linked to in your question for the information that got me started on this answer!

    0 讨论(0)
  • 2020-12-12 12:43

    This is very similar to @Inafziger's answer, but a more concise set of code, with the added benefit that the check for "Release" is done with a checkbox in XCode rather than a runtime variable:

    enter image description here

    Follow these instructions twice, dragging one to the beginning and one to the end (one to run before build and one to run after build):

    # xcode-build-bump.sh
    # @desc Auto-increment the build number every time the project is run. 
    # @usage
    # 1. Select: your Target in Xcode
    # 2. Select: Build Phases Tab
    # 3. Select: Add Build Phase -> Add Run Script
    # 4. Paste code below in to new "Run Script" section
    # 5. Drag the "Run Script" below "Link Binaries With Libraries"
    # 6. Ensure that your starting build number is set to a whole integer and not a float (e.g. 1, not 1.0)
    # 7. Check the checkbox "Run script only when installing"
    
    buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${PROJECT_DIR}/${INFOPLIST_FILE}")
    buildNumber=$(($buildNumber + 1))
    /usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "${PROJECT_DIR}/${INFOPLIST_FILE}"
    

    See https://gist.github.com/sekati/3172554

    0 讨论(0)
提交回复
热议问题