I'm trying to build an xcode project and run it through the iPhone Simulator via applescript. I'm aware of xcodebuild but it doesn't let you run the app in the simulator. I've gotten pretty close with the script below...
tell application "Xcode"
set targetProject to project of active project document
tell targetProject
set active build configuration type to build configuration type "Debug"
set active SDK to "iphonesimulator3.0"
end tell
if (build targetProject) is equal to "Build succeeded" then
launch targetProject
end if
end tell
... but the build command doesn't seem to obey the active SDK property, it always defaults to the project's base SDK setting (such as the iPhoneOS3.0 instead of iPhonesimulator3.0)
Is there a way to tell the build command to use a specific SDK? I'm using xcode 3.2 on snow leopard.
Here is the trick... you have to set the SDKROOT build setting. Here is a zsh script I use to find the xcode project within the current hierarchy, build it, and run it via xcode.
#!/bin/zsh
BUILD_PATH=$(dirname $0)
while [[ -z $BUILD_FILE && $BUILD_PATH != "/" ]]; do
BUILD_FILE=$(find $BUILD_PATH -name '*.xcodeproj' -maxdepth 1)
BUILD_PATH=$(dirname $BUILD_PATH)
done
if [[ -z $BUILD_FILE ]]; then
echo "Couldn't find an xcode project file in directory"
exit 1
fi
# Applescript likes's : instead of / (because it's insane)
BUILD_FILE=${BUILD_FILE//\//:}
# Find the latest Simulator SDK
SIMULATOR_SDKS=( /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/*.sdk )
SIMULATOR_SDK=${SIMULATOR_SDKS[-1]}
SIMULATOR_SDK_STRING=$(basename ${(L)SIMULATOR_SDK%.[a-z]*})
if [[ -z $SIMULATOR_SDK ]]; then
echo "Couldn't find a simulator SDK"
exit 1
fi
osascript <<SCRIPT
application "iPhone Simulator" quit
application "iPhone Simulator" activate
tell application "Xcode"
open "$BUILD_FILE"
set targetProject to project of active project document
tell targetProject
set active build configuration type to build configuration type "Debug"
set active SDK to "$SIMULATOR_SDK_STRING"
set value of build setting "SDKROOT" of build configuration "Debug" of active target to "$SIMULATOR_SDK"
if (build targetProject) is equal to "Build succeeded" then
launch targetProject
else
application "iPhone Simulator" quit
end if
end tell
end tell
SCRIPT
Another option to consider is to use Applescript to launch a shell script that executes the xcodebuild program. xcodebuild allows you to specify things like a specific target, configuration, sdk, etc. I use this all the time when I have to SSH into a build server and rebuild a project.
The iphonesim project gives you a command-line launcher for the iPhone simulator.
If the set active SDK command does not work as expected, a workaround would be to create another build configuration named "Debug-Simulator" (in Xcode in the project settings), and to set the base SDK in the new configuration to iphonesimulator3.0. This would allow you to select the SDK by selecting the build configuration (if that works in AppleScript).
Related
I have installed macOS Ventura – the latest version of macOS – and I would like to have a stable version of Xcode (e.g. 13.4.1) running. However, it says "The version of Xcode installed on this Mac is not compatible with macOS Ventura."
Is there any way to run Xcode on Ventura?
Xcode 14 is required by macOS Ventura. But if, in case you want to use your old version of Xcode (e.g Xcode 13), you can launch it directly from the finder or from the terminal.
To open in finder navigate to:
Applications Folder > Find Xcode App > Right click on the app and
click on Show Package Contents > Open Contents > Open
MacOS > and launch Xcode.
Or
Run the following command in the terminal:
open /Applications/Xcode.app/Contents/MacOS/Xcode.
Single-run script to fix the problem
As this problem in principle is the same problem as last year, when we wanted to run Xcode 12 on macOS Monterey, it is worth to check last year's question on the same problem. There, I found this great answer in which a script is proposed that only needs to be run once to fix the problem (allowing a regular opening of Xcode 13, e. g. via double click). The script works by changing the build version of the old Xcode 13 to the build version of the new Xcode 14, thereby tricking the OS.
Before running the script, you need to change the OLD_XCODE and NEW_XCODE variables to the correct path.
#!/bin/sh
set -euo pipefail
# Set the paths to your Old/New Xcodes
OLD_XCODE="/Applications/Xcode-13.4.1.app"
NEW_XCODE="/Applications/Xcode-14.1.0.app" # To get build number
# Get New Xcode build number
OLD_XCODE_BUILD=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" ${OLD_XCODE}/Contents/Info.plist)
NEW_XCODE_BUILD=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" ${NEW_XCODE}/Contents/Info.plist)
echo The Old Xcode build version is $OLD_XCODE_BUILD
echo The New Xcode build version is $NEW_XCODE_BUILD
# Change Old Xcode build version to New Xcode
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion ${NEW_XCODE_BUILD}" ${OLD_XCODE}/Contents/Info.plist
# Open Old Xcode (system will check build version and cache it)
open $OLD_XCODE
# Revert Old's Xcode's build version
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion ${OLD_XCODE_BUILD}" ${OLD_XCODE}/Contents/Info.plist
For my future self, when I prematurely upgrade my macOS to the latest version.
Since I'm using Xcode just for a building purposes for my Flutter app and I don't really care about Xcode UI, all I needed to do is:
Download the desired xcode version app from https://xcodereleases.com
Unzip the app and rename it to Xcode-<version>.app
Move it to /Applications directory
Run xcode-select command: xcode-select -s /Applications/Xcode-<version>.app
Confirm that the correct Xcode version is selected with xcode-select -p
That's it.
That way I can have multiple Xcode app versions and I can quickly switch between them.
After updating my Xcode to the latest version 14.0. I am facing this issue if anyone know how to resolve it please let me know
Click properties on the project, go to build phases and check the option "For install builds only"
Maybe the problem is with "Run script"
Ex: I did change firebase crashlytics from "pod" to "Packeges".
But I not change script.
I have tried all the solutions in
"https://stackoverflow.com/questions/53289524/xcode-10-2-1-command-phasescriptexecution-failed-with-a-nonzero-exit-code"
My solutions is change TARGETS -> Build Phases. In the script field
form
"${PODS_ROOT}/FirebaseCrashlytics/run"
to
"${BUILD_DIR%/Build/*}/SourcePackages/checkouts/firebase-ios-sdk/Crashlytics/run"
In short the problem is your script, do it right
If Scrip is install builds only. U need
Targets -> Build Phases -> Run Scrip -> check "For install builds only"
Ex:
APP_PATH=“${TARGET_BUILD_DIR}/${WRAPPER_NAME}”
# This script loops through the frameworks embedded in the application and
# removes unused architectures.
find “$APP_PATH” -name ‘*.framework’ -type d | while read -r FRAMEWORK
do
FRAMEWORK_EXECUTABLE_NAME=$(defaults read “$FRAMEWORK/Info.plist” CFBundleExecutable)
FRAMEWORK_EXECUTABLE_PATH=“$FRAMEWORK/$FRAMEWORK_EXECUTABLE_NAME”
echo “Executable is $FRAMEWORK_EXECUTABLE_PATH”
EXTRACTED_ARCHS=()
for ARCH in $ARCHS
do
echo “Extracting $ARCH from $FRAMEWORK_EXECUTABLE_NAME”
lipo -extract “$ARCH” “$FRAMEWORK_EXECUTABLE_PATH” -o “$FRAMEWORK_EXECUTABLE_PATH-$ARCH”
EXTRACTED_ARCHS+=(“$FRAMEWORK_EXECUTABLE_PATH-$ARCH”)
done
echo “Merging extracted architectures: ${ARCHS}”
lipo -o “$FRAMEWORK_EXECUTABLE_PATH-merged” -create “${EXTRACTED_ARCHS[#]}”
rm “${EXTRACTED_ARCHS[#]}”
echo “Replacing original executable with thinned version”
rm “$FRAMEWORK_EXECUTABLE_PATH”
mv “$FRAMEWORK_EXECUTABLE_PATH-merged” “$FRAMEWORK_EXECUTABLE_PATH”
done
On my side this issue appeared when i change my computer and issue was caused by Apple Silicon processor. When i start to use m1 pro, i did not check the installation page i directly intalled flutter via Fvm. When i check the installation page i saw there are a few steps to install flutter on Apple Slicon. And these steps fixed the issue;
sudo softwareupdate --install-rosetta --agree-to-license
ref: https://docs.flutter.dev/get-started/install/macos
Is it possible to send an html email report through a monkey talk automation tool. If it is possible please provide any code or url.
Thanks,
Ramakrishna.
Use a CI (continuous Integration tool) with monkeytalk.
like jenkins+monkeytalk it is bit hard to configure it. but it can be done. use jenkins to automate the process of checkout code from repository and write a shell script to build the project and runtest cases with monkeytalk. after finish tests jenkins will email the reports to the given recipients.
jenkins: http://jenkins-ci.org/
More details...
first of all you need to download and deploy Jenkins. Downloadlink
to deploy in terminal
$ java -jar jenkins.war
open a browser http://localhost:8080 will take you to Jenkins dash board.
There is link for Jenkins settings on left side menu: from that page you can set an email account , password for Jenkins. and then provide recipient email addresses. so if a build faild Jenkins will email all console errors to the recipents. (try reading Jenkins documentation if it hard to install)
Then create a new job giving a name and details . add your repository URL and type add user credientials to it. and configure the rest in the end of the page you can give a build command as a shell script or ant file or there are many options.
then save the job and edit configurations start a build if it not checkout your code from repo and build correctly copy the errors from error console and search in google.
here is a sample code for build a Xcode project to a simulator
echo "Build Start"
/usr/bin/xcodebuild -target FuncTest CODE_SIGN_IDENTITY="iPhone Distribution: Leapset Inc." PROVISIONING_PROFILE="xxxxxxxx-1216-4E86-97D5-xxxxxxxxxxxx" OTHER_LDFLAGS="-lxml2 -all_load -lstdc++" DSTROOT="build" VALID_ARCHS="armv7 armv7s i386" -arch i386 -sdk iphonesimulator6.0 -configuration Release clean build install;
echo "Build End"
if you need to open iPhone simulator with the app use
# open app in simulator
echo "Start run app in simulator"
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone\ Simulator.app/Contents/MacOS/iPhone\ Simulator -SimulateApplication release-1.081/Leapset/build/Release-iphonesimulator/LeapsetFuncTest.app/FuncTest & disown;
echo "DONE run app in simulator"
run tests
echo "start run Test jobs"
######### Job 1 #########
echo
echo "TEST: SignInOut.mts"
echo "DISCRIPTION: sign in and out with user credintials"
#java -jar $$ROOTPATH/monkeytalk/LeapsetTest/libs/monkeytalk-runner-1.0.43.jar -agent IOS $ROOTPATH/monkeytalk/LeapsetTest/signinUser.mt
java -jar monkeytalk/LeapsetTest/libs/monkeytalk-runner-1.0.43.jar -agent IOS monkeytalk/LeapsetTest/SignInOut.mts
and monkey talk will generate reports. only thing you need to find is some way to attach those html reports to the Jenkins There are so many plugging available for Jenkins.
above commodes are working fine but you need to give the corrects paths to work it. like for above build command
Note: this command should run in terminal inside the project root directory(where the Xcode project file is)
Good luck
:)
xocdebuild command help
xcodebuild
[-project <projectname>]
[[-target <targetname>]...|-alltargets]
[-configuration <configurationname>]
[-arch <architecture>]... [-sdk [<sdkname>|<sdkpath>]]
[-showBuildSettings] [<buildsetting>=<value>]... [<buildaction>]...
xcodebuild
[-project <projectname>] -scheme <schemeName>
[-configuration <configurationname>]
[-arch <architecture>]... [-sdk [<sdkname>|<sdkpath>]]
[-showBuildSettings] [<buildsetting>=<value>]... [<buildaction>]...
xcodebuild
-workspace <workspacename> -scheme <schemeName>
[-configuration <configurationname>]
[-arch <architecture>]... [-sdk [<sdkname>|<sdkpath>]]
[-showBuildSettings] [<buildsetting>=<value>]... [<buildaction>]...
xcodebuild -version [-sdk [<sdkfullpath>|<sdkname>] [<infoitem>] ]
xcodebuild -list [[-project <projectname>]|[-workspace <workspacename>]]
xcodebuild -showsdks
Following on from my question How to run an xcode project from bash?
I've found the built *.app in the build directory, but I'm trying to figure out how to get xcode to open it as it can't just be run as a Mac OS X program.
Any ideas?
thanks to chuan at this post: XCode Test Automation For IPhone
I'm stuck with the same problem trying to launch my debug output from building my xcode project. I just experimented with the following
open ./prog.app&
seems to do the trick.
I've solved my problem using a bash file that uses rsync to sync working directories and then AppleScript which builds and runs the project.
sync.sh:
#!/bin/bash
# script for moving development files into xcode for building
developmentDirectory="/"
xcodeDirectory="/"
echo 'Synchronising...'
rsync -r $developmentDirectory $xcodeDirectory \
--exclude='.DS_Store' --exclude='.*' --exclude='utils/' --exclude='photos'
echo 'Synchronising Done at:'
echo $(date)
buildandrun:
set projectName to "projectName"
# AppleScript uses : for / in directory paths
set projectDir to "Users:username:Documents:" & projectName & ":" & projectName & ".xcodeproj"
tell application "Xcode"
open projectDir
tell project projectName
clean
build
(* for some reasons, debug will hang even the debug process has completed.
The try block is created to suppress the AppleEvent timeout error
*)
try
debug
end try
end tell
quit
end tell
Then, finally, I'm using a shell script called run.sh aliased in my .bash_profile:
run.sh:
#!/bin/bash
bash utils/sync.sh
osascript utils/buildandrun
Can everything which is done through Xcode GUI be done through command line, like changing app name, changing provisional profile, distribution profile? If yes then how. May be it can be done through xcodebuild , but till now i am only able to compile through xcodebuild.
Yes. Building can be done through xcodebuild:
$ xcodebuild -help
Usage: xcodebuild [-project <projectname>] [-activetarget] [-alltargets] [-target <targetname>]... [-parallelizeTargets] [-activeconfiguration] [-configuration <configurationname>] [-sdk <sdkfullpath>|<sdkname>] [-xcconfig <filepath>] [<buildsetting>=<value>]... [<buildaction>]...
xcodebuild [-version [-sdk [<sdkfullpath>|<sdkname>] [<item>] ]
xcodebuild [-showsdks]
xcodebuild [-find <binary> -sdk <sdkfullpath>|<sdkname>]
xcodebuild [-list]
…but I see you already know that. The application name can be changed by simply editing the Info.plist file. And I think you can change the profiles by hacking the *.pbxproj file (it’s a regular text file). You can save a copy of the project file, change a profile through the IDE and then diff the new version and the saved copy to see the changes:
$ find . -name '*.pbxproj'
./Source/Foo.xcodeproj/project.pbxproj
$ cp Source/Foo.xcodeproj/project.pbxproj ~/Desktop
# …now changing the profile through IDE…
$ diff Source/Foo.xcodeproj/project.pbxproj ~/Desktop/project.pbxproj
517d516
< "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "…";
534d532
< "PROVISIONING_PROFILE[sdk=iphoneos*]" = "…";
But it depends on what you are trying to do. You could switch the profiles much easier by setting different profiles for different build modes (Debug/Distribution/Whatever).