xcodebuild: error: Failed to build workspace. Reason: A build only device cannot be used to run this target - ios

I'm trying to build and test on device (iPhone) using command line:
xcodebuild \
-workspace MyApp.xcworkspace \
-scheme MyApp \
-destination 'generic/platform=iOS,id=iPhoneUUID' \
clean test
But I'm getting this error:
xcodebuild: error: Failed to build workspace MyApp with scheme MyApp.
Reason: A build only device cannot be used to run this target.
Any of you knows why I'm getting this error?
I'll really appreciate any help.

Cut off the generic part in your -destination value. Else Xcode won't try to build for your device, but for the generic build only device:
xcodebuild \
-workspace MyApp.xcworkspace \
-scheme MyApp \
-destination 'platform=iOS,id=iPhoneUUID' \
clean test

Related

Xcode 14.2 Unable to close provisioning ledger entry because not all of its subentries are closed

Xcode 14.2 command line tools archive failed.
xcodebuild -allowProvisioningUpdates \
-workspace $WORKSPACE \
-scheme $SCHEME \
archive \
-configuration Release \
-archivePath $ARCHIVEPATH \
ONLY_ACTIVE_ARCH=NO \
EXCLUDED_ARCHS="" | xcpretty;
** ARCHIVE FAILED **
For whom might facing the problem:
This might be the update that required the "-sdk" flag to avoid the error.
i.e.
-sdk iphoneos

Got an Archive failed when trying "xcodebuild archive" in terminal

I have created a framework with few cocoapod dependencies
.The archive for the framework is failing when i do 'xcodebuild archive' after adding the pod files (Did pod install).
In the normal build, it is working fine. There is no error and the build is successful but when I do 'xcodebuild archive' on my terminal got this below issue.
error: no such module 'Lottie'
import Lottie
^
** ARCHIVE FAILED **
The following build commands failed:
CompileSwift normal arm64 /Users/surya/Documents/Projects/Sampe\ lottie\ test/TestFramework/TestFramework/ViewController.swift
CompileSwiftSources normal arm64 com.apple.xcode.tools.swift.compiler
(2 failures)
Below is my xcode build archive command
xcodebuild archive \
-scheme TestFramework \
-destination "generic/platform=iOS" \
-archivePath ../Output/TestFramework.framework-iphoneos.xcarchive \
SKIP_INSTALL=NO \
BUILD_LIBRARY_FOR_DISTRIBUTION=YES
Found the answer - we need to add - workspace ProjectName.xcworkspace, if our framework uses pods. Check the below command
xcodebuild archive -workspace projectName.xcworkspace \
-scheme projectName \
-sdk iphonesimulator \
-archivePath "./archives/ios_Simulators.xcarchive" \
BUILD_LIBRARY_FOR_DISTRIBUTION=YES \
SKIP_INSTALL=NO

"xcodebuild test" keeps breaking my info.plist file

I am trying to test my Unity application on a simulator from command line but when I try to do it, the info.plist file is broken by xcodebuild test.
Here is how I try to do it :
#!/usr/bin/env bash
set -e
xcodebuild \
-project "Tests.ios/Unity-iPhone.xcodeproj" \
-scheme "Unity-iPhone" \
-sdk iphonesimulator \
-derivedDataPath Tests \
-destination "platform=iOS Simulator,name=iPhone 11,OS=13.4" \
test
ENABLE_BITCODE=NO
The error I get is this one :
Testing failed:
Unity-iPhone Tests:
tests.app encountered an error (Failed to install or launch the test runner. (Underlying error: Failed to install the requested application. The bundle identifier of the application could not be determined.))
When I look in the info.plist after the xcodebuild test, there is only two lines :
LastAccessedDate
WorkspacePath
The info.plist was correct before the xcodebuild.
When I try to do it directly from xcode (Product => Test, with the simulator), it succeeds perfectly.
However, when I try to do it directly from xcode after trying to do it with xcodebuild, it fails with the same error than xcodebuild.
Does someone knows how to get rid of this error ?

How to specify output dir name for ios simulator when using xcodebuild cli in combination with a xcworkspace?

I build a xcode (6.3.1) project that uses workspace because I'm using Pods.
When I do:
xcodebuild \
build \
-workspace MyProject.xcworkspace \
-scheme MyProject \
-configuration Debug \
-sdk iphonesimulator \
-ARCHS=i386 \
VALID_ARCHS=i386 \
SYMROOT="/tmp/build/emulator" \
SHARED_PRECOMPS_DIR="/tmp/build/sharedpch"
It outputs the app to:
/tmp/build/emulator/Debug-iphonesimulator/MyProject.app
Is there a way with the xcodebuild command to get it build to
/tmp/build/emulator/MyProject.app
I have tried to replace SYMROOT with
CONFIGURATION_BUILD_DIR="/tmp/build/emulator"
Now it builds to
/tmp/build/emulator/Monsenso.app
but that do not work smoothly with CocoaPods frameworks (e.g. Typhoon for DI) ~ build fails with:
The following build commands failed:
GenerateDSYMFile /tmp/build/emulator/Typhoon.framework.dSYM /run/emulator/Typhoon.framework/Typhoon

Travis builds failing - Reason: The run destination iPad 2 is not valid for Testing the scheme 'UIKitPlus-Example'

I'm having some trouble with my cocoapods running Travis CI. Everything seems to install correctly, but the xcodebuild script fails
$ set -o pipefail && xcodebuild test -workspace Example/UIKitPlus.xcworkspace -scheme UIKitPlus-Example -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO | xcpretty -c
xcodebuild: error: Failed to build workspace UIKitPlus with scheme UIKitPlus-Example.
Reason: The run destination iPad 2 is not valid for Testing the scheme 'UIKitPlus-Example'.
The command "set -o pipefail && xcodebuild test -workspace Example/UIKitPlus.xcworkspace -scheme UIKitPlus-Example -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO | xcpretty -c" exited with 70.
https://travis-ci.org/JamieREvans/UIKitPlus/builds/54649639
I'm not sure why this is failing, because I can run my tests on the iPad 2 simulator, using that scheme, without any issues.
Is this a Travis issue or is my Travis script wrong?
I've managed to get it build by adding a destination to the xcodebuild command line, e.g. -destination "platform=iOS Simulator,name=iPhone 6"

Resources