How to change build setting versioning in Xcode 11 using script? - shell

Since Xcode 11 had change Version to $(MARKETING_VERSION) & Build to $(CURRENT_PROJECT_VERSION)
there are new field in build setting
How can I change this value with script due to
xcrun agvtool new-version
xcrun agvtool new-marketing-version
not work perfectly as it on Xcode 10
I tried this one https://stackoverflow.com/a/58164679/7332815 but not working
I can only get correct value from
echo $versionNumber
echo $buildNumber
but how can I set new value to it?

update 2022/08/19
if using fastlane to bumping version
desc "Bump version and build nubmer"
lane :bump_version_and_build_number do |options|
version_number = options[:version]
puts version_number
sh("sed -i '' -e 's/MARKETING_VERSION \\= [^\\;]*\\;/MARKETING_VERSION = #{version_number};/' ../${YOUR_PROJECT_NAME}.xcodeproj/project.pbxproj")
increment_build_number
end
and just type in commend line
bundle exec fastlane bump_version_and_build_number version:1.0.1
okey I find a solution for myself, and thanks to an friend from meetup.
for Version number
I used
sed -i '' -e 's/MARKETING_VERSION \= [^\;]*\;/MARKETING_VERSION = 3.4.5;/' ${YOUR_PROJECT_NAME}.xcodeproj/project.pbxproj
e.g. sed -i '' -e 's/MARKETING_VERSION \= [^\;]*\;/MARKETING_VERSION = 3.4.5;/' DemoProject.xcodeproj/project.pbxproj
note that this can't work in pre-action of scheme setting
As for Build version
I used xcrun agvtool new-version xxx
e.g. xcrun agvtool new-version 3.4.5b
you can write these command in Build Phases
the reason I don't use xcrun agvtool new-marketing-version 3.4.5b is because it will write solid number into plist.
And I agree with Manuel's answer in Post
With these I can manage multi-targets' versioning
p.s. If you want to do that to, for example, notificationService target, remember to change version and build number manual at first to make Xcode 11 change the corresponding value to an variable like this
or you can make that by edit plist in source code of course.
That's the closest method I achieve to manage multi-target versioning so far.

Related

Bash Script Not Able To Find .JAR file

So I'm trying to make an automated bash script to help build certain versions of the Minecraft Spigot server. In order to "build" the server, you have to decompile the .jar file by running the following commands in the terminal.
export MAVEN_OPTS="-Xmx2G"
export JAVA_HOME="/usr/libexec/java_home -v 1.8" (Omit this line unless you are building a previous version then the current 1.13 build, which uses Java 11 and not Java 8)
java -jar BuildTools.jar (Optional: --rev flag can be used to dictate what version you would like to download of the server)
Now this is what I have come up with so far to make a simple "double click and done" bash script. I'm extremely new to running, compiling, writing, etc of bash scripts. The error I'm getting is something along the lines of "Can't find BuildTools.jar", however this is blocked by a pop up from my terminal that I can't get rid of and still see the message. Once I click ok, it just closes the window.
#!/bin/sh
cd "$( dirname "$0" )"
export MAVEN_OPTS="-Xmx2G"
export JAVA_HOME="/usr/libexec/java_home -v 1.8"
exec java -jar BuildTools.jar --rev 1.8.8
My main objective is to just be able to edit the script manually and dictate what version I would like to download by changing the --rev flag, and deleting the "java version" line if not using the current 1.13 build.
Ideally I would like the script once run, to ask me what version I would like to use. If i hit enter it omits the --rev flag & java version line, and downloads the current version (1.13), if I specify a version (i.e. "1.9") it runs the export JAVA_HOME="/usr/libexec/java_home -v 1.8" line and adds the --rev flag to the end of the exec line.
If this doesn't make any sense, here is the article explaining how to do what I'm doing through the terminal with no "automated script".
https://www.spigotmc.org/wiki/buildtools/
I would like to get this script to work as I would forward this script along to other server developers that would be able to use the script in their every day development and not have to run multiple commands through the terminal every time they want to build a server.
The easiest way to do something like this is to take a single optional argument:
java -jar BuildTools.jar --rev "${1-1.8.8}"
This may look a bit clunky, but it means the script can be called like my_script.sh to use the default version or my_script.sh 2.0 to use version 2.0.
Another simple improvement would be to pull out a variable for the default version:
default_version='1.8.8'
java -jar BuildTools.jar --rev "${1-$default_version}"
Your shebang line uses /bin/sh, which is not the same as Bash. This may make your script very slightly more portable than using Bash, but Bash is by now very common, and you can take advantage of Bash features in your script. For example:
You can declare the default version variable constant with readonly default_version.
You can get the script path more reliably.

xcodebuild archive: set version number and build number

I'm writing a bash script to archive and export my project so I can send it to iTunes Connect. However, the documentation from the command line is a little confusing. I'm trying to figure out if there's a way to pass a parameter to the xcodebuild command that would set the version number and build number for that archive (similar to how you pass -scheme MyScheme when calling xcodebuild). Anyone done something like this before?
Thanks!
You can use this:
/usr/libexec/Plistbuddy -c "Set CFBundleVersion $SBUILD_NUMBER" "$PLIST"
/usr/libexec/Plistbuddy -c "Set CFBundleShortVersionString $BUNDLE_SHORT_VERSION" "$PLIST"
with PLIST is the path to your Info.plist

How to get the path of latest SDK available on Mac

I know that in order to get xcode install directory from command line I have to use xcode-select -print-path. The result is something like: /Applications/Xcode.app/Contents/Developer
Is there any command to get latest SDK folder? I need as result something like: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/
If it's not possible to get the SDK complete path I need at least SDK number and I'll try to build the path.
The easiest way I found so far is:
xcrun --show-sdk-path
To be more precise,
xcrun --sdk macosx --show-sdk-path
I'm sure this could be cleaned up a bit, and probably done in a single line of perl, but here's an easy approach:
sdkparam=`xcodebuild -showsdks | awk '/^$/{p=0};p; /OS X SDKs:/{p=1}' | tail -1 | cut -f3`
sdkpath=`xcodebuild -version $sdkparam Path`
The point of the awk is to print the "OS X SDKs" block from -showsdks. Then take the last line of it and the 3rd field (it's separated with tabs). Then we ask xcodebuild for the path to that sdk.

Is there any way to get an XCode build setting to vary according to build ACTION (e.g. clean, rebuild)?

I'm trying to figure out exactly how schemes work in xcode and what they're for. I have a cross-platform product that's built on OS X using an external build system ( scons ). I'd like to be able to build/debug it from Xcode, mostly because of the symbol search and the debugger. I've been using eclipse CDT which mostly works well, but has some quirks.
I can mostly get this to work by creating an empty project and adding an 'external build system' target. Then, as part of the 'Info' of the target, I specify the 'Build Tool' as /usr/local/bin/scons, and the 'Arguments' are the build parameters that I send to scons. Basically I have the following build variables called $(TARGET) and $(BUILD_TYPE) that vary according to whether the build is debug or release, so those can be specified as conditional 'Build Settings'.
The problem is I'd like Menu->Project->Clean to work. It looks like Xcode/xcodebuilder use the $(ACTION) variable to pass this on - where $(ACTTION) is either 'build', 'clean', or some other build actions. See xcodebuild ACTION. Scons is a bit different - it has a built-in clean action that's invoked on the command line with scons -c. So my first thought was to use a conditional 'Build Setting' to pass this parameter, but it turns out that conditional 'Build Settings' don't seem to vary based on the build ACTION - just the build architecture and SDK.
Is it possible to add an expression to a 'Build Setting' in Xcode/xcodebuilder? Is there another good way that I could get 'Clean' to work in Xcode with scons?
Write a wrapper script for SCons, and put it in your project. For example:
External Build Tool Configuration
Build Tool: $(PROJECT_DIR)/scons-xcode-wrapper.sh
Arguments: $(ACTION)
Wrapper Script
From an experiment, it looks like $(ACTION) is empty when building, and set to clean when cleaning.
#!/bin/sh
cd "$PROJECT_DIR"
case $1 in
clean)
scons -c
;;
*)
scons
;;
esac
Don't forget to chmod +x your script.
With SCons, you can programatically set the build to perform a clean using the SetOption() function. The clean option and others that can be set are listed here.
The problem is that SCons treats command line options that arent in the form "--option" or "option=value" as targets. So its not possible to cause something like scons clean to perform a clean. I tested with the Alias() function and could not get it to work.
If you have the option to change the string that xcode uses for $(ACTION) to something like clean=1 then you could something like the following to programatically do a clean:
env = Environment()
if ARGUMENTS.get('clean') == '1':
print "Setting clean"
env.SetOption('clean', True)
print env.GetOption('clean')
...
This will cause a clean:
scons clean=1
You could also consider the AddOption(), but this only allows for options with -- prepended
Set your 'Arguments' parameter to end with:
--$(ACTION)
This will translate to:
scons [all your arguments] --clean
If you check the docs for scons here, you can see that --clean works just as well as -c
Clean is the only one that works however, the other build actions always come through blank.
You can use a combination of the answers above, namely:
Set your arguments to something like --xcode-action=$(ACTION).
Put code in your SConstruct like this:
env.AddOption('--xcode-action',
dest='xcode_action',
type='string',
action='store',
default='',
help='The action Xcode wishes to perform')
if GetOption('xcode_action') == 'clean':
SetOption('clean', True)
This is basically the solution I'm using in scons-xcode.

Delete App on Simulator through Command Line

Im writing an automated test that will use the Instruments automator to run a series of UX tests on my application. The problem is, I need the app to run on a fresh install for the specific set of tests that I am running. Is there a way to delete an app in the simulator through the command line?
Specifically, I am looking for something like this:
xcodeBuild -delete myApp.app
Something like this might work, although I haven't fully tested it:
rm -rf ~/Library/Application\ Support/iPhone\ Simulator/6.0/Applications/*
Substitute the proper simulator version number for the 6.0 of course.
I actually ended up using the solution found here: https://stackoverflow.com/a/5128616/608739
The apple script works great and gets around all those pesky simulator issues.
--------------- OLD POST -------------------
Using jpancoast's lead, I modified his script to find and clear the latest version of the app on simulator:
CURRENT_SDK=""
if [ -z "$RUN_ON_SPECIFIC_DEVICE_OPTION" ] ; then
CURRENT_SDK=$(xcodebuild -showsdks | grep 'iphoneos[0-9].[0-9]' | grep -o '[0-9].[0-9]' | head -n1)
else
CURRENT_SDK=$(xcodebuild -showsdks | grep 'iphonesimulator[0-9].[0-9]' | grep -o '[0-9].[0-9]' | head -n1)
fi
rm -rf ~/Library/Application\ Support/iPhone\ Simulator/"$CURRENT_SDK"/Applications/*
The script checks to see if we are currently running on device or not. It then finds the folder corresponding to the latest SDK (assuming your project is building on that SDK) and deletes all applications associated with that SDK version. Further refinement can be made to only delete specific apps you are interested in.
Assuming you know the iOS version and the name of the app, this is a script I put together to remove a single app. It comes in handy if you don't want to reset the entire simulator and lose all other installed apps.
The script below is part of a larger script I use, but should work as shown. I've got this saved as simulator-uninstall.sh, you can then uninstall an app using something like:
./simulator-uninstall.sh ios=7.1 app="My App"
Here's the script (note, bash is not my strong point, but this worked for me!):
#!/bin/bash
for p in "$#"; do
# Parse out each param which needs to be of the form key=value
# Then remove any quotes around the value, because we will quote all vars anyway
IFS="=" read argkey argvalue <<< "$p"
argvalue="${argvalue%\"}"
argvalue="${argvalue#\"}"
case $argkey in
ios) IOS_VERSION=$argvalue
;;
app) APP_NAME=$argvalue
;;
esac
done
SIMULATOR_ROOT="$HOME/Library/Application Support/iPhone Simulator/$IOS_VERSION"
# Find the *.app directory
APP_PATH=`find "$SIMULATOR_ROOT/Applications" -name "$APP_NAME.app"`
if [ "$APP_PATH" ]; then
# Ensure simulator isn't running whilst we remove the app
killall "iPhone Simulator"
# Get the parent directory - this will be a UUID, then remove it
APP_DIR=`dirname "$APP_PATH"`
rm -rf "$APP_DIR"
echo "Removed $APP_DIR"
else
echo "App $APP_NAME not found for platform version $IOS_VERSION"
fi
Hope that helps!

Resources