iOS: How to upgrade my CFBundleVersion and my CFBundleShortVersionString automatically in Xcode 11? (My old script doesn't work anymore)

只愿长相守 提交于 2019-12-23 21:35:16

问题


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.

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, 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?


回答1:


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>



回答2:


You can try with:

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

from this



来源:https://stackoverflow.com/questions/58131830/ios-how-to-upgrade-my-cfbundleversion-and-my-cfbundleshortversionstring-automat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!