Is there way to build iphone app on the command line with xcodebuild, then automatically deploy the app to a USB-connected iphone device and run some unit testing on device?
Right now, I can do this under xCode with "Build and Run", but I'm looking for solution to do this outside of the xCode GUI environment.
Thanks
You can script Xcode using Applescript, and run Applescript scripts from the command line.
There more on how to script Xcode in this answer.
Related
I would like to launch app installed at iPhone device from terminal for development and testing.
I watched the below question and answer.
Launching instruments from command line with iPhone simulator
However I am using Mountain Lion and there are no such below file or path.
/Developer/Platforms/iPhoneOS.platform/Developer/Library/Instruments/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate
Would you tell me about how to use such automation launching of Instruments?
I had the very same problem a couple of days ago. Seems that starting from Xcode 4.4 Apple moved it to /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Instruments/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate
But in Xcode 4.5 I didn't find this directory as well. So I continued my search and found tracetemplate file in /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate
BTW, there's a nice shell script which automates running stuff. All you need is to replace INSTRUMENTS_TEMPLATE with a proper path in automation.sh
I have been trying to write a script that builds and deploys a iphone project to the simulator. When I build the project in xcode it works fine, however when I build the project in the command line, it crashes in the simulator.
I am using the following command to build the app.
xcodebuild -project MyAppSourceCode/trunk/MyApp.xcodeproj -target "MyApp" -sdk iphonesimulator4.3
The build proces completes without errors. The simulator is running sdk4.3. I can build the app in xcode then manually replace the .app file in the simulator directory and it still crashes. This is a cocos2d app. Any suggestions?
EDIT:
I deployed the app in the simulator by first trying the "iphonesim" program described here: How do you deploy an iPhone app to the simulator from the command line?
Second, I tried the simulator command for launching the app without copying it to the simulator directory: ~/../../Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone\ Simulator.app/Contents/MacOS/iPhone\ Simulator -SimulateApplication ~/MyAppSourceCode/trunk/build/Release-iphoneos/MyApp.app/MyApp
This method results in the simulator launching then displaying a pop up message that says: "The simulated application quit."
When that didn't work I wrote a script that copies the MyApp.app to the simulator directory. After you copy the MyApp.app into the simulator directory, you can launch it from the simulator, but it crashes immediately after launch.
Take note that by default command line builds with xcodebuild use the RELEASE configuration. In Xcode the default is DEBUG.
That means you may have a crash bug that only occurs in release builds. To verify try running the app within Xcode in the release configuration by modifying the scheme to build the release configuration.
I am attempting to run the iOS simulator from the command line. I have found the location where the iPhone Simulator can be run from. My question is whether or not it can receive parameters to specify which device should be launched and what app it should run.
$ ./Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone Simulator.app/Contents/MacOS/iPhone\ Simulator
Does anyone know if there are tricks to this. Knowing more about this would really help with our Continuous Integration process.
We now use WaxSim to automate our iOS applications during CI Builds
Use the -SimulateApplication argument to run your executable in the simulator (executable inside the .app bundle)
(you could also compile the project from the command-line like this:)
xcodebuild -project Test.xcodeproj -arch i386 -sdk iphonesimulator
Then for example:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone\ Simulator.app/Contents/MacOS/iPhone\ Simulator -SimulateApplication Test.app/Test
or
./Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone Simulator.app/Contents/MacOS/iPhone\ Simulator -SimulateApplication Test.app/Test
To launch a specific device you can do:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone\ Simulator.app/Contents/MacOS/iPhone\ Simulator -SimulateDevice "iPhone Retina (3.5-inch)"
Try this in your shell for Xcode 6
osascript -e 'activate application "iOS Simulator"'
For Xcode 7
osascript -e 'activate application "Simulator"'
If you want to open Simulator with specific app installed then you can use some of the ready utility to launch simulator. This way it is easy to install the app and run on the simulator. This are the command line utilities that can be run from Terminal Window.
iPhoneSim
ios-sim
Other are same as above two.
And main thing is all uses same approach to open simulator. (see the project for more details)
Other way (not recommended by me) use script file to run from command.
You can use xcrun simctl to list available simulators, launch applications, etc. This tool is present in both Xcode 7 and Xcode 8. If you don't give it a command it will print command line help.
xcrun simctl launch <UUID> <bundle id of app> will start the application.
I'm using google unit testing code.
I'm building it quite nicely with xcodebuild on the command line. Now I want to run it (preferably on attached Device but simulator would also work) and catch all the feedback from the tests.
But I can't find out how to run it. Any ideas?
Jeff Haynie's iphonesim project on Github looks like it could work. I had trouble building 27812bb4b (make failed on a warning in nsprintf.m), but that may just be me using a pre-release OS and SDK. See also this related question.
If you followed the instructions from the Google page (creating the target, adding the test files to the target) and you have an iPhone SDK certificate (you need it to upload apps to the device) you can just change the Active SDK to your device (upper left corner combo in XCode)
If you don't have a certificate, you need to apply to the SDK program.
The only iPhone simulator and debugger I'm aware of comes with the iPhone SDK. In order to use the iPhone SDK you need to have an Intel-based mac with OS 10.5 Leopard installed, in which case you might as well be programming/compiling in XCode instead of using the command line.
There has to be some misunderstanding here. What exactly do you want to run from the command line? The test suite? If so, the test suite should be a separate target, so that all you have to do is build it, for example like this:
xcodebuild -target UnitTests -sdk iphonesimulator2.2.1 -configuration Debug
If you have the testing target configured correctly, it will run the RunIPhoneUnitTest.sh shipped with the Google Toolbox and the script will run all your tests.
I can already build an app with a distribution profile via the command line
xcodebuild -configuration Distribution -sdk iphoneos3.0 clean build
However, I'd like to go one step further and install the app to the connected iPhone and execute it ( as if I'd pressed Build and Run in XCode ).
The final command listed in the build commands window ( cmd+shift+B ) is CodeSign, which as far as I know just signs the code and nothing else. So I'm not sure what command ( if any is available ) I can run from the command line to install and run the app on the iPhone.
I'm running the official SDK, not a jailbroken phone.
If you have a post build script you should be able to install it and run it using a script. If you're jailbroken you should be able to use SCP and then execute it directly.
There may be an AppleScript or automator way of solving the problem as well.
I've written a blog entry on how to install apps on a connected iPad / iPhone without using Xcode or iTunes. This method does NOT require JailBreak - any iOS device will work. Only works on the Mac though.
This method allows you to run a Terminal command to install an iPA file.
http://pervasivecode.blogspot.co.uk/2012/06/install-ios-app-ipa-file-without-xcode.html