问题
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