Xcode 7: Xcode cannot run using the selected device - xcode

After upgrade to Xcode 7, Xcode cannot run tests on simulator.
$ xcodebuild test -sdk iphonesimulator -scheme MyProject
Build settings from command line:
SDKROOT = iphonesimulator9.0
xcodebuild: error: Failed to build project MyProject with scheme MyProject.
Reason: Xcode cannot run using the selected device.
The issue is reproduced on Travis CI and Jenkins. It's worked fine when I run xcodebuild test on a local machine.

I've gotten past this error by adding a flag like -destination 'name=iPhone 6'. It seems like xcodebuild used to pick a default destination but isn't doing that anymore. =|
I'm going to see if there is anything I can set in the build scheme to avoid hard coding a device.

Related

Running tests for Swift package using xcodebuild: Error tests must be run on a concrete device

I am trying to run tests for my Swift package (defined by Package.swift) by using xcodebuild:
xcodebuild -scheme "package-name-Package" -configuration "Debug" -sdk "iphonesimulator14.5" -arch "x86_64" test`
Unfortunately, I keep getting this error:
xcodebuild: error: Failed to build workspace package-name with scheme package-name-Package.
Reason: Cannot test target “Target1Tests” on “Any iOS Simulator Device”: Tests must be run on a concrete device
Cannot test target “Target2Tests” on “Any iOS Simulator Device”: Tests must be run on a concrete device
Cannot test target “Target3Tests” on “Any iOS Simulator Device”: Tests must be run on a concrete device
I'm not sure what -sdk to use. I've read the output of xcodebuild -showsdks and chosen appropriately (I need to build/ test for iOS). I've tried iphoneos iphonesimulator, iphoneos15.0, iphonesimulator15.0, iphonesimulator14.5, iphoneos14.5 as the sdk. (both Xcode 12 and Xcode 13 beta, by using xcode-select)
Thanks for the upvote kind stranger, I did manage to figure it out: There are 2 ways.
The main solution is to use -destination instead of -sdk. Okay, 🧠 _dump:
Swift Package inside an Xcode Workspace (WorkspaceName.xcworkspace)
My preferred option: I ended up putting the Swift Package in an Xcode workspace. By this I mean dragging the root directory containing the Swift Package (and also the Workspace) into the Xcode project navigator/ workspace.
The advantage is the Xcode schemes are not generated every time you launch Xcode, but are associated with the workspace instead. This means your modifications are not reset every time you launch Xcode (e.g. adding environment variables).
xcodebuild -workspace ./WorkspaceName.xcworkspace -scheme SchemeName -destination 'platform=iOS Simulator,name=iPhone 12' test
Notes:
If you want to build the project, just set the correct scheme and replace test with build
Here is a list of destinations available on Xcode 13 Beta. An example is: { platform:iOS Simulator, id:FD90A730-A1D5-4BBC-B61A-0324400EE9EA, OS:15.0, name:iPhone 12 }
you can get SchemeName from the Xcode workspace or by running xcodebuild -list
The destination used is platform=iOS Simulator,name=iPhone 12. You can get a list of destinations from xcodebuild -workspace ./WorkspaceName.xcworkspace -scheme SchemeName -showdestinations in a directory that contains an Xcode project, workspace or package.
I got it working by just selecting the platform and name properties, without specifying OS or `ID. This is nice because the CI system might right a different Xcode with different OS, though you might prefer to specify it.
You need to format the destination correctly, xcodebuild prints them out in json, but you should provide them in comma separated with equals signs.
Swift Package without an Xcode Workspace
If you don't have a workspace, you can do:
Run xcodebuild -list
Pick the scheme that makes the most sense (probably the scheme that says your-package-name-is-here-Package)
Run:
xcodebuild -scheme SchemeName -destination 'platform=iOS Simulator,name=iPhone 12' test
Caveat: Actually make sure you don't have a workspace in the same directory. (i.e. one that doesn't contain your Swift Package, because Xcode gets confused.) If it sees a workspace, it won't detect the autogenerated Xcode schemes based on the Package.swift in the current directory.

xcodebuild gives signing error when it shouldn't

I execute the following xcodebuild command line:
xcodebuild CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO
-workspace "MyThing.xcworkspace" -scheme "MyScheme"
-configuration 'Debug' -sdk iphoneos clean build
and get this error:
error: An empty identity is not valid when signing a binary
for the product type 'Application'. (in target 'MyTarget')
This used to work. How can I fix it?
This is using Xcode 10.2.1.
For whatever reason, this seems to be (yet another) strange side effect of using Xcode's new build system. You can fix this from the xcodebuild command line by forcing use of the legacy build system, using the following flag:
-UseModernBuildSystem=0
To set up your project/workspace to use the legacy build system for everything, see here.
NOTE: While one can apparently still use it for a bit longer (in June 2022), the legacy build system is marked deprecated in Xcode 13.4.1)

xcodebuild fails, but building from Xcode succeeds

I'm trying to automate my build using xcodebuild.
However, my xcodebuild fails while building static libraries, complaining that it can't find headers that are part of dependency frameworks.
No problem to build from Xcode.
Why is the result of xcodebuild different from the one of Xcode?
You might accidentally build the Xcode project instead of the Xcode Workspace from xcodebuild.
If this is the case, replace:
xcodebuild -project "<*yourProjectFile*>.xcodeproj"
with:
xcodebuild -workspace <*yourWorkspaceFile*>.xcworkspace
After fixing this I get the exact same results from Xcode and xcodebuild.

xcodebuild failed to build workspace with scheme. Reason - There is nothing to test

I have app with UITests target in Xcode 8.
I can run tests fine using Xcode. Now m trying to run them using command line.
xcodebuild test build-for-testing test-without-building -workspace
a.xcodeproj/project.xcworkspace -scheme testtargetscheme -destination
id=deviceuid -only-testing:StartupTestSuite
But it fails with: xcodebuild failed to build workspace with scheme. Reason - There is nothing to test.
I have checked scheme settings and made sure it does have tests enabled. I also tried above command with normal app run scheme, for which also I have test configured properly.
Any ideas?

xcodebuild: build Mac OS app

I'd like to do automating for my Mac App project.
My environment is Mac OS 10.8.3; Xcode 4.6.
I use the following command in the terminal:
xcodebuild -project pro.xcodeproj -target MyProject -configuration Debug CODE_SIGN_IDENTITY='Mac Developer: xxxxxx'
It ran well and I could see the MyProject.app was created in the workspace: /build/Debug.
Then I just copied it to the Jenkins configurations, like:
export DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer/
xcodebuild -project pro.xcodeproj -target MyProject -configuration Debug CODE_SIGN_IDENTITY='Mac Developer: xxxxxx'
However, the build always failed with :
Code Sign error: Provisioning profile 'EADA149E-1A30-4C3C-B42B-75DEA77308DF' can't be found
What makes me strange is that I could not find the "wrong" profile.
I find a same question Distributing .app file after command line xcodebuild call. But the "archive" is invalid in xcode 4.6.
So please help me about how can I do the automating for Mac App.
Thanks!
I find it and it is the same problem like "provison not found".
What you need to do is delete the referred provision file in prom.xcodeproj/project.pbxproj.
You can find the same answers here Codesign error: Provisioning profile cannot be found after deleting expired profile

Resources