update CFBundleShortVersionString with script gives error in Xcode 11

China☆狼群 提交于 2020-06-29 05:05:12

问题


I am trying to update with this script my extension app which is inside the main app. In general when i commit with svn, the version of my main app update, now i need to update the extension version also. I am trying to use the following script but seems it gives error. any idea?

this is the example:

version_number=$1
build_number=$2
#
echo "version_number is $version_number"
echo "build_number is $build_number"



pruvitInfoPlist="ServiceExtension/Info.plist"
/usr/libexec/PlistBuddy -c "Set CFBundleShortVersionString $version_number" $pruvitInfoPlis

The Error:

> Build/file.rb:41: syntax error, unexpected unary-, expecting do or '{'
> or '(' /usr/libexec/PlistBuddy -c "Set CFBundleShortVersionSt...
>                         ^ Build/file.rb:41: syntax error, unexpected tGVAR, expecting end-of-input ...ersion_number" $pruvitInfoPlist ...  
> ^~~~~~~~~~~~~~~~ Command PhaseScriptExecution failed with a nonzero
> exit code

回答1:


I am going to Answer my question here maybe in can help someone else. I resolved the issue with script in extension.

plistFile = "#{ENV['BUILT_PRODUCTS_DIR']}/#{ENV['INFOPLIST_PATH']}"
`/usr/bin/plutil -convert xml1 "#{plistFile}"`
unless pl = Plist::parse_xml(plistFile) 
    puts "Could parse #{plistFile}"
    exit
end

freshPlFile = "#{ENV['SOURCE_ROOT']}/ServiceExtension/Info.plist"
`/usr/bin/plutil -convert xml1 "#{freshPlFile}"`
unless freshPl = Plist::parse_xml(freshPlFile)
    puts "Could parse #{freshPlFile}"
   exit
end




version = pl["CFBundleShortVersionString"].gsub(/ \([a-f0-9 \/:]*\)/, '')
# keep only the major and minor version number and add the revision
version.gsub!(/([^\.]*)\.([^\.]*).*/, "\\1.\\2.#{revision}");


pl["CFBundleShortVersionString"] = version
pl["CFBundleVersion"] = Time.now.utc.strftime("%Y%m%d%H")

pl.save_plist(plistFile)

`/usr/bin/plutil -convert binary1 #{plistFile}`

puts "#{plistFile}:"
puts "CFBundleVersion = #{pl["CFBundleVersion"]}"
puts "CFBundleShortVersionString = #{pl["CFBundleShortVersionString"]}"

every time i commit it update my extension and my main app. you need to add this script also in main app.



来源:https://stackoverflow.com/questions/62520154/update-cfbundleshortversionstring-with-script-gives-error-in-xcode-11

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