Build and run an app on simulator using xcodebuild - ios

I have the following goal to achieve: build and run an .app application using xcodebuild and ios-sim.
I'm using the following script to build the application.
xcrun xcodebuild \
-scheme $XCODE_SCHEME \
-project $XCODE_PROJECT \
-configuration Debug \
-destination generic/platform=iOS \
-derivedDataPath \
build
Then for running it, I'm using
ios-sim launch MyApp.app/ --devicetypeid "iPhone-6-Plus, 9.1"
Each time I receive the following message:
Program specified by service does not contain one of the requested
architectures: ?
What is happening, that the app doesn't run?
Note: if I run the second command (ios-sim...) against the .app built from Xcode (the one contained in derived data) the procedure works fine.

Ok. Figured out the issue.
You need to specify the correct destination. For example.
xcrun xcodebuild \
-scheme $XCODE_SCHEME \
-project $XCODE_PROJECT \
-configuration Debug \
-destination 'platform=iOS Simulator,name=iPhone 6 Plus,OS=9.1' \
-derivedDataPath \
build
In this way Xcode will create the folder (called build) containing your products (in particular look at Debug-iphonesimulator). The build dir is created within the dir you are running the xcodebuild command.
Now you can point that folder in order to run the ios-sim command (see ios-sim for more references) or simctl (see iOS 8: Building custom simulators and Build And Run iOS Apps In Commmand Line for more info).

Related

using Jenkins for iOS build

I am new to jenkins, I am trying to build my iOS application on simulator via jenkins. I am using this command,
xcrun xcodebuild -project Name.xcodeproj \
-scheme Name \
-sdk iphonesimulator \
-destination 'platform=iOS Simulator,OS=15.5,name=iPhone 12' \
CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO \
build
The build is successful but I can't see the application built on my simulator. And How can I build the same app on real device via jenkins?
The command that you are running will build the application FOR the simulator (this usually means that it will build the application for the 64-bit architecture).
That doesn't mean that it will actually copy/install the application to the simulator for you, its literally just building the application with that architecture so that it is compatible with the simulator.
To build for device, replace your destination with -destination generic/platform=iOS you would also need code signing

Not able to build Xcode project on real device

I am facing a strange issue:
I am trying to build using this xcode command
xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination ‘id={deviceID}' test
But every time I run this command I see an unusual prompt that shows up in the next line --
quote]
I am not sure what quote means and what I am expected to enter. I tried entering other device attributes but still it din help me .
Could some one please help me?
As far as I understand your provided information you are trying to start a test on a real device. Tests are executed on simulator only, which is why Xcode tells you it's not able to build your project.
Try something like this instead:
xcodebuild \
-project WebDriverAgent.xcodeproj \
-scheme WebDriverAgentRunner \
-sdk iphonesimulator \
-destination 'platform=iOS Simulator,name=iPhone 6,OS=8.1' \
test
As you can see this command tries to build your project on an iPhone 6 simulator with iOS 8.1 installed. You can define this to your liking (e.g. OS=13.0 or another iPhone/iPad).
You can give these reads a try, too, for more examples and a better understanding:
https://www.mokacoding.com/blog/running-tests-from-the-terminal/
https://www.appsdeveloperblog.com/run-xcode-unit-tests-from-the-command-line/

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.

create UI Test in Xcode 8 via terminal

Is there a way to actually create UI Tests in Xcode8 via the terminal? I am aware that UI Tests are usually created via Xcode itself but i would like to do it via the terminal and automate the whole process. Thanks!
you can use xcodebuild command to run the test in Xcode.
like:
xcodebuild -workspace ${WORKSPACE_NAME} \
-scheme ${SCHEME_NAME} \
-destination "${DESTINATION}" \
-derivedDataPath "${OUT_PATH}" \
test
do not forget to set the scheme shared.

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.

Resources