Xcodebuild test hangs indefinitely without error - ios

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

Related

Building and launching app in Simulator from terminal

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.

How to build Xcode project from the command line?

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

xcrun error domain=FBSOpenApplicationErrorDomain, code=1

I'm trying to build an app via the command line, using these commands:
xcodebuild PRODUCT_BUNDLE_IDENTIFIER=com.myapp \
PROVISIONING_PROFILE="XXXX-XXXX-XXXX-XXXX-XXXX" \
CUSTOM_URL="http://mycustomurl.com" \
-project AppName.xcodeproj \
-scheme AppName \
-sdk iphoneos \
-configuration AppStoreDistribution archive -archivePath $PWD/build/AppName.xcarchive
then:
xcodebuild -exportArchive \
-archivePath $PWD/build/AppName.xcarchive \
-exportPath AppName.app \
-exportFormat app
Now, I would like to run this app to test using the emulator, so I run these commands to install and launch the app:
xcrun -v simctl install booted AppName.app #Install
xcrun simctl launch booted com.myapp #Launch
The app instantly closes and xcrun comes back:
An error was encountered processing the command (domain=FBSOpenApplicationErrorDomain, code=1):
The operation couldn’t be completed. (FBSOpenApplicationErrorDomain error 1.)
Now, if I try to launch my app with xcode (by gui) this starts without any problems.
I've also tried to:
Reset the Emulator
Check the App Transport Security Settings
Close all instance of the app
You're building for iphoneos (I can see a "-sdk iphoneos" parameter in your xcodebuild command line). Then you're trying to install the resulting .app object onto the simulator (!!).
That will produce an architecture mismatch, and thus that cryptic runtime error.
Change your compilation commands from "-sdk iphoneos" to something like "-sdk iphonesimulator9.3" (in case this is the version you need).
If in doubt, type "xcodebuild -showsdks" and a list of installed SDK's will appear on screen. Choose the one you need.
You'll probably need to mess with -arch parameter also and change it from ARM to i386 (Remember the Simulator runs onto your intel MAC ).
Try and tell us if it works.

xcode build works on device, but not on simulator

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.

xcode Code to install app

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

Resources