I want to setup a jenkins server to build our app and run javascript/automation tests on a simulator.
Regarding that topic, I had several issues to launch the app on the simulator. Now I am fighting with the hole simulator thing.
My plan is, to build the app and to launch it on the simulator. Here is what Ive done:
Step 1:
(make archive)
xcodebuild -project "myApp.xcodeproj" -scheme "api-dev" -configuration "Debug Dev" -destination 'platform=iOS Simulator,name=iPhone 5s,OS=8.1' archive -archivePath /Users/name/Desktop/build/archive/myApp.xcarchive
Step 2:
(make/export .app file)
xcodebuild -exportArchive -exportFormat app -archivePath /Users/name/Desktop/build/archive/myApp.xcarchive -exportPath /Users/name/Desktop/build/myApp.app
Step 3:
(using xcrun to boot simulator)
xcrun simctl boot < device_id >
Step 4:
(using xcrun to install app on booted simulator)
xcrun simctl install booted /Users/name/Desktop/build/myApp.app
Step 5:
(shutdown simulator, since it would crash when I use instruments afterwards)
xcrun simctl shutdown < device_id >
Step 6:
(start .js tests via instruments)
instruments -w 'iPhone 5s (8.1 Simulator)' -t "/Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.xrplugin/Contents/Resources/Automation.tracetemplate" /Users/name/Desktop/build/myApp.app -e UIASCRIPT /Users/name/Projects/project-name/myAppTests/UITests/script.js
When I open the simulator to launch the installed App (so without Step 6), only to test if I can open and launch the App, it does not work. Thats my real issue at the moment.
Error: "Target failed to run: Failed looking up pid of launched process"
When I open Xcode and take a real device and copy "/Users/name/Desktop/build/myApp.app" on it, it totally works fine...
What do I miss here with the Simulator?
Thank you for your input.
Related
I'm having troubles while running XCUITests on iPhone and paired apple watch (simulators) simultaneously using terminal. I can do it by hitting "test button" for each of my uitests targets separately, it works just fine, but I need to do it
1 - from command line
2 - simultaneously
However, I am able to run uitests from command line for the same iPhone simulator (that is paired with apple watch simulator) using
xcodebuild -workspace MyApp.xcworkspace -scheme 'MyApp' -destination 'name=iPhone 11' test
It works as expected- launches simulator and run tests
The problem is:
When I do the same for paired apple watch (it doesn't matter separately or simultaneously with this iPhone) tests for apple watch doesn't launch at all
xcodebuild -workspace MyApp.xcworkspace -scheme 'MyApp WatchKit App' -destination 'name=iPhone 11' test
Terminal says that:
The requested device could not be found because no available devices matched the request.
Available destinations for the "WatchTesterApp WatchKit App" scheme:
{ platform:iOS Simulator, id:2B6CA009-BF6B-4437-9E80-18D53EB003BA, OS:14.5, name:iPhone 11 }
But this device is here and listed as available
So, any suggestions? maybe someone had similar issue?
I will appreciate any help
So, after a long investigation and a long list of possible fixes that resolved nothing, I updated Xcode and tried to run the same command, which didn't work either and only after creating new clean project using new Xcode it finally worked.
I used:
xcodebuild test -workspace WatchTesterAppExample.xcworkspace -scheme 'WatchTesterAppExample WatchKit App' -destination 'platform=WatchOS Simulator,name=Apple Watch Series 7 - 45mm' &
xcodebuild test -workspace WatchTesterAppExample.xcworkspace -scheme 'WatchTesterAppExample' -destination 'platform=iOS Simulator,name=iPhone 13'
It worked for me on the simulators, didn't try it on real device yet
Interesting fact: I am still able to see this error in some case, especially when I don't specify platform in the 'destination'
I wanted to build and launch my iOS app using a shell script and not Xcode. My question is the similar to this question: How to launch an iOS app in the simulator without XCode rebuilding the app, which was asked in 2012.
It says that the IPA file created in build directory within the project directory can be used. I could not find a build directory inside my project folder. Also, I want to build the app from a script.
What is the most latest way of building and running an app on simulator using terminal commands?
Edit:
I built the app from command line:
xcrun xcodebuild \
-scheme UITestingTutorial \
-project UITestingTutorial.xcodeproj \
-configuration Debug \
-destination 'platform=iOS Simulator,name=iPhone 11,OS=13.6' \
-derivedDataPath \
build
But how do I launch it now?
Running this script inside your project directory will launch the app programmatically.
xcrun xcodebuild \
-scheme UITestingTutorial \
-project UITestingTutorial.xcodeproj \
-configuration Debug \
-destination 'platform=iOS Simulator,name=iPhone 11,OS=13.6' \
-derivedDataPath \
build
open -a "Simulator"
# This simulator id has been manually found
# by running 'xcrun simctl list' and searching
# for iPhone 11 under iOS 13.6 under Devices
# A script can be written to automatically find this.
xcrun instruments -w 3100E7BC-0B95-4B3E-B0DC-8743FFCB731A
xcrun simctl install 3100E7BC-0B95-4B3E-B0DC-8743FFCB731A ./build/Build/Products/Debug-iphonesimulator/UITestingTutorial.app (http://uitestingtutorial.app/)
xcrun simctl launch 3100E7BC-0B95-4B3E-B0DC-8743FFCB731A com.codepro.UITestingTutorial
You can refer to Launch apps in iOS Simulator using Terminal for more details. Please note the xctool is deprecated.
Xcodebuild hangs indefinitely in Jenkins. But same setup works properly in local machine.
(Xcode 7.3.1, OS X 10.11.6)
Command executed (After clearing DerivedData & Clean)
xcodebuild -scheme APP_SCHEME -derivedDataPath ./DerivedData -sdk iphonesimulator -destination 'OS=9.3,name=iPhone 6' ARCHS=x86_64 VALID_ARCHS=x86_64 ONLY_ACTIVE_ARCH=NO GCC_GENERATE_TEST_COVERAGE_FILES=YES GCC_INSTRUMENT_PROGRAM_FLOW_ARCS=YES test
Launches app in simulator and then Hangs indefinitely after following command without any error
touch APPSCHEME.xctest
xcodebuild hangs because it is not able to find & launch the appropriate simulator.
Verify whether the below 2 commands gives the matching list of simulators and they are in available state.
- xcrun simctl list
- instruments -s devices
If not, then proceed on to do a clean uninstall of Xcode,install and then try running the command again
Delete Xcode from Applications folder
In ~/Library/Developer/ Delete Xcode and CoreSimulator folder
sudo rm /Library/Preferences/com.apple.dt.Xcode.plist
sudo rm -r ~/Library/Caches/com.apple.dt.Xcode
sudo rm -r ~/Library/Application\ Support/Xcode/
Clean Trash
Restart Install Xcode ,Launch and Accept license Agreement and then Restart
I've tried reading the Xcode Tools documentation Apple provides, so that I can use the Terminal to build a .app file and run the resulting app on the Simulator. Essentially what I want to do is do the same thing as Cmd + R does on Xcode.
So far I've attempted to build my .xcodeproj like this:
xcodebuild -configuration Debug build
However, when I install & run it on the Simulator I get an app w/ a black screen:
// Boot device
xcrun simctl boot "iPhone 7"
// Install app
xcrun simctl install "iPhone 7" "/Users/.../MyApp/build/Debug-iphoneos/MyApp.app"
// Open simulator
open /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app
// Launch app using its bundle id
xcrun simctl launch booted "com.example.apps.MyApp"
Not to mention the xcrun simctl launch booted "com.example.apps.MyApp" line never terminates and on the Simulator it keeps trying to open and reopen the app, but the app only ever shows a black screen.
If anyone could tell me what I'm doing wrong with the building of the.xcodeproj that would be great!
After having a working configuration in Xcode, open a shell and navigate to the directory, where your <NAME>.xcodeproj resides.
After running:
xcodebuild -list -project <NAME>.xcodeproj/
you see a list of Schemes.
Copy the desired scheme name and run:
xcodebuild -workspace <WORKSPACE NAME> -scheme <SCHEME NAME> build
You can install [ios-deploy][1] i.e. via:
npm install -g ios-deploy
Copy the app path from the end of the xcodebuild output and run:
ios-deploy --debug --bundle <APP PATH>
Now the app should be launched on i.e. a connected device.
[1]: https://github.com/phonegap/ios-deploy
I want to achieve with the code, I write the program to install other applications to the phone, I found online said to be to app unzip and copy to the / var / mobile / Applications directory, I follow suitHowever, the installed program, you must restart the phone to display and install the application can not run
You can combine xcodebuild and xcrun commands to install and run your app.
The xcodebuild compile your project and create a .app file in DSTROOT that um point.
xcodebuild -sdk iphonesimulator8.4 -arch i386 install DSTROOT=~/MyApp
if you are using some pod file you have .xcworkspace instead .xcodeproj then add -workspace and -scheme at your xcodebuild.
xcodebuild -sdk iphonesimulator8.4 -arch i386 -workspace MyApp.xcworkspace -scheme MyApp install DSTROOT=~/MyApp
After created the .app file you can run into a Simulator device.
xcrun instruments -w "iPhone 6 (8.4 Simulator)"
xcrun simctl install booted ~/MyApp/Applications/MyApp.app
if you want to run in another Simulator device, try see all devices available.
xcrun instruments -s