Showing the build command Xcode uses - ios

Is there a way to see the xcodebuild command that Xode uses for building?
I have created a library file with Xcodebuild command from Terminal. But there are some differences between the files generated from terminal and Xcode UI.

I use this behavior to switch to the log when building starts.
.
In the log you can find all the commands Xcode is executing.

Related

command fails on jenkins, but works on terminal

I'm working on using fastlane screengrab/snapshot to take screenshots of my android and ios app. When I run them locally on terminal, they work perfectly, but when I run them from jenkins, they fail. I'm using macOS.
Android:
/Users/shared/Library/Android/sdk/tools/emulator -avd Pixel_API_22 &
fastlane screengrab
(These 2 are in a .sh)
The first line failed: PANIC: Cannot find AVD system path. Please
define ANDROID_SDK_ROOT
iOS:
fastlane snapshot
it failed while trying to build a test because of an provisioning profile error:
xcodebuild -showBuildSettings -scheme UITests -project ./abc.xcodeproj
(this is a command that fastlane snapshot execute automatically)
Again, they both run smoothly on terminal (I ran them in the same workspace as junkins)
Double-check the environment settings after executing your job in Jenkins: you might see differences with the same environment settings as seen with your user account in command-line (where it is working)
The username might be different (if your Jenkins server/agent runs with another account).
The OP Son Nguyen confirms the PATH issue:
the developer who set up jenkins put a wrong path to android sdk, so I was able to run the android part by fixing the path.
And the OP adds:
fastlane was installed in /usr/local/bin while jenkins was in /User/myUser: So, somehow they didn't work well together.
I reinstalled fastlane in /User/myUser and it worked.
This got it working for me.
I had to include this at the top of my script :
#!/bin/zsh
source ~/.zshrc
and my .zshrc had this:
export PATH="$PATH:"/usr/local/bin/
export SSL_CERT_FILE=/etc/ssl/cert.pem # for openssl error
export ANDROID_HOME=/Users/jenkins/Library/Android/sdk

Cordova Build Creates xcarchive not an ipa. Why?

I am using Cordova to create and build my application. Today (12/12/17), I am using the current version of everything (cordova, xcode, etc). When I run:
cordova build ios --device --release
at the end of the build process that happens, I get no errors. But I do get this message:
Exported myappname.xcarchive to:
/Users/.../platforms/ios/build/device
** EXPORT SUCCESS **
I don't see anywhere in build logs that a .ipa file was created. Just a stupid .xcarchive.
Note: I cannot to edit project information or settings in XCode manually, because I am running this Cordova command as part of automated build process. I should be able to create an .ipa via Cordova CLI, without having to open XCode.
If you're having the same experience I did, check the actual physical directory for the .ipa file. Turns out even though my build log never said so, the .ipa file was actually being built alongside the .xcarchive. It should be in /platforms/ios/build/device/myappname.ipa.

Running an Applescript after build phase in Xcode

I have an Applescript that opens the Safari developer tools. This saves me from the hassle of clicking Develop -> Inspect -> index.html every time I build a Cordova / Phonegap app.
I would now like to invoke this Applescript when I build the project and open it in the simulator.
I've tried adding a building phase and adding the script as instructed in https://developer.apple.com/library/ios/recipes/xcode_help-project_editor/Articles/AddingaRunScriptBuildPhase.html.
However when I build the project in XCode I'm getting an error: "auto_opendevtools.applescript: bad interpreter: Permission denied". Seems all the permissions are fine.
How I entered the script in the build phase:
Leads to error:
The "Add Run Script Build Phase" need a shell command or a path of the shell script.
To run an AppleScript from a shell script, you must use the osascript command.
osascript "/the path of/auto_opendevtools.applescript"

Build and Run iOS7 app through command line

I want to build, run and publish iOS7 app using the command line tool. I am not getting any good sources for it. Can someone help me out with a good tutorial which will help me in writing a shell script to build my xcode project through command line and not through xcode build option.
Apple has a well documented tutorial on this :
https://developer.apple.com/library/ios/technotes/tn2339/_index.html
The build command goes like this :
xcodebuild -scheme MyiOSApp build

Can't run UIAutomationTest from command line

I have an iOS application, and I want to put it in continuous integration. The strategy I'm using to do that is trying to run the tests from the command line.
I'm trying to do it using the following script:
TRACETEMPLATE="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Instruments/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate"
instruments -t $TRACETEMPLATE build/Release-iphonesimulator/MyApp.app -e UIACSCRIPT "UnitTests/SomeTest.js"
SomeTest.js is a simple javascript file that I can run in Instrumentation inside Xcode and it works. I build my application using:
xcodebuild -alltargets -sdk iphonesimulator5.1
and this generates the MyApp.app. I can run the application from Xcode in the simulator just fine, however, when I try to run by the instruments, I get a box saying that there is an unknown error and in the command line it prints:
2012-05-15 15:32:59.928 instruments[17548:1d03] Recording cancelled : At least one target failed to launch; aborting run
Instruments Trace Error : Failed to start trace.
Can anyone give me any help/suggestions about what might be happening and how can I fix this?
Also, it always open the iPad simulator? Can I make it that it opens any simulator I want?
I was getting this same error and nearly pulled my hair out trying to solve it. The error messages are completely unhelpful.
What ended up being the problem for me was the .app file that I was pointing to. Once I found the "right" .app file that was deeply buried in the 5.1 Simulator folder, I was able to finally run UIAutomation tests from the command line with Xcode 4.3.
The path to the .app that worked for me:
~/Library/Application\ Support/iPhone\ Simulator/5.1/Applications/{string-of-numbers-and-letters}/MyApp.app/
Here is the full command I'm using to run UIAutomation tests from the command line with Xcode 4.3:
instruments -t /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Instruments/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate ~/Library/Application\ Support/iPhone\ Simulator/5.1/Applications/{string-of-numbers-and-letters}/MyApp.app/ -e UIASCRIPT /Path/To/TestFile.js
Hope this helps someone else, as the documentation out there for this is extremely lacking.
Update
Note that as of Xcode 4.5.2, the automation template location has changed from that on my original answer:
/Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate
The correct location of the Automation.tracetemplate, as of Xcode 4.5.2, is /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate
The paths for the command line invocation of UIAutomation has changed slightly over the past couple of years. I have written a few bash shell scripts that work together which can launch your UIAutomation test file in a way that works with Xcode 4.4.1.
See this gist: https://gist.github.com/3605692#comments
In a nutshell, the key command ends up being:
instruments -t $INSTRUMENTS_TEMPLATE $APP_PATH -e UIASCRIPT $SCRIPT_PATH -e UIARESULTSPATH $RESULTS_PATH
My scripts show the variable substitutions needed. The other benefit is that iOS simulator apps have often changing GUID as part of their path. My script will find them, so you don't have to hard code the temporary GUID in your builds / scripts / command line invocations.
sorry, my english is very bad.
As the easiest way to run this script from Teamtsity? Each assembly - the numbers and letters are different.
Not the easiest way:
clean the simulator prior to assembly
find the folder with the program, and it contains these numbers and letters, written in the variable.
This variable, such as writing the script.
Maybe there's a way easier to take from these numbers?
The Build Configuration should be debug than Release. That was the reason for the error in my case.
You can change Build Configuration in 'Edit Schemes' and by choosing the Profile tab. Verify that build tab also is in debug mode.
I did the ps command to see which processes are running. I found that instruments was still running. I then did killall instruments and that killed the instruments process. I then did my instruments command and it worked perfect after that.

Resources