4

I have a script that upgraded my version (0.01 by 0.01) and my build (1 by 1). It doesn't work anymore with the Xcode 11.

enter image description here

Here is my script:

    #!/bin/bash
    rm -rf build

    Version=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "$INFOPLIST_FILE")
    Version=$(echo "scale=2; $Version + 0.01" | bc)

    Build=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$INFOPLIST_FILE")
    Build=$($Build + 1)

    /usr/libexec/PlistBuddy -c "Set :CFBundleVersion $Build" 

    "$INFOPLIST_FILE"
        if [ "${CONFIGURATION}" = "Release" ]; then
        /usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $Version" "$INFOPLIST_FILE"    
fi 

Here is the Error message I have now when I want to build or archive in Xcode:

Details

Failed to install the requested application
Domain: NSPOSIXErrorDomain Code: 22
Failure Reason: The application's Info.plist does not contain CFBundleShortVersionString.
Recovery Suggestion: Ensure your bundle contains a CFBundleShortVersionString.
User Info: {
bundleURL = "file:///Users/olosta/Library/Developer/Xcode/DerivedData/Formbox-cxaxehrhmxqaqabbijmxvasgmhwn/Build/Products/Debug-iphonesimulator/Formbox_Renault_BusinessDays.app/";
}

I checked that ticket, but it doesn't help me for the script

If I go in Xcode/General/Identity, I can see that the "Version" and the "Build" are filled in the Xcode, enter image description here but if I check my info.plist by manually opening it, both values are empty

   <key>CFBundleVersion</key>               <string></string>    
   <key>CFBundleShortVersionString</key>    <string></string>

If I fill them manually directly in the plist, it works but it seems that the values from Xcode are not stored in that fields anymore? What do you think?

Cœur
  • 37,241
  • 25
  • 195
  • 267
ΩlostA
  • 2,501
  • 5
  • 27
  • 63
  • Why not set both `CFBundleVersion` and `CFBundleShortVersionString` regardless of `$CONFIGURATION`? – trojanfoe Sep 27 '19 at 09:47
  • @trojanfoe because I just want the Version upgrading with the archiving, and the build each time I compile, or build or archive etc... That part works well, no problem. – ΩlostA Sep 27 '19 at 09:49
  • Well it looks to me like you are generating an invalid `Info.plist`. Just *increase* `Version` when arciving but always set it. – trojanfoe Sep 27 '19 at 09:50
  • 1
    I've just post this answer at [here](https://stackoverflow.com/a/58636744/7332815) hope it help! – andrew54068 Oct 31 '19 at 04:03

2 Answers2

5

You can try with:

versionNumber="$MARKETING_VERSION"
buildNumber="$CURRENT_PROJECT_VERSION"

from this

dt dino
  • 1,194
  • 6
  • 19
  • If you question is a dupe then why answer it? – trojanfoe Sep 27 '19 at 12:59
  • @dt dino Oh, it is interesting, that is why there is problems, they changed something in the info.plist. I try to get it in the script, but impossible to set the New CURRENT_PROJECT_VERSION... – ΩlostA Sep 27 '19 at 14:28
2

Here is the complete script. I tried it with old and new projects.

 #!/bin/bash
rm -rf build

Build=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$INFOPLIST_FILE")
Version=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "$INFOPLIST_FILE")

if [ "${Build}" = "" ]; then
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion 1" "$INFOPLIST_FILE"   
else
Build=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$INFOPLIST_FILE")
Build=$(echo "scale=0; $Build + 1" | bc)
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $Build" "$INFOPLIST_FILE"
fi
if [ "${Version}" = "" ]; then
/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString 1.00" "$INFOPLIST_FILE"
else
Version=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "$INFOPLIST_FILE")
Version=$(echo "scale=2; $Version + 0.01" | bc)
if [ "${CONFIGURATION}" = "Release" ]; then
/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $Version" "$INFOPLIST_FILE"
fi
fi

EDIT:
For completing the solution, I added that keys in the plist. I changed the existing values by:

<key>CFBundleShortVersionString</key>
    <string>1.00</string>
    <key>CFBundleVersion</key>
    <string>1</string>
ΩlostA
  • 2,501
  • 5
  • 27
  • 63
dt dino
  • 1,194
  • 6
  • 19
  • Thks it works. It is strange because the marketing version is not changing anymore, but it works. Very strange. I will see if it is a tolerance from Apple for now, may be they don't allow it later and I may find the way to upgrade the "marketing version"... – ΩlostA Sep 30 '19 at 09:10
  • for me adding CFBundleShortVersionString to my plist was the solution, thanks for freeing me up on this one. – Eman Jul 15 '22 at 21:46