xcodebuild gives signing error when it shouldn't - xcode

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)

Related

Does xcode use "xcodebuild" under the hood?

Does xcode use of the xcodebuild command behind the scenes to build?
If so, how can I find the exact xcodebuild command that is run?
I checked the report navigator but couldn't find it in there.
I would have thought that running xcodebuild -sdk iphonesimulator -configuration Debug -project <myproject>.xcodeproj -scheme <myscheme> would be identical to selecting product -> build in xcode (with a scheme/destination matching the command line), but they seem to have slightly different behavior.
For example, when running the command line above with the -showBuildSettings option, I noticed that BUILD_ACTIVE_RESOURCES_ONLY=NO even though it should be set to YES according to the target's build settings. When running product -> build from xcode, the build settings logs (generated by following #Slipp D. Thompson's answer here) show BUILD_ACTIVE_RESOURCES_ONLY=YES.
There are few other strange differences I noticed as well.
No. One could do an experiment: move all xcodebuild binaries in some local folder and check that Xcode still able to build some application.
Since Apple presents xcodebuild as a self contained command line tool for building Xcode projects, it is reasonable to suspect that use code sharing between both tools.

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.

Xcode 7: Xcode cannot run using the selected device

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.

How do I change the XCode build location to Legacy using the console?

Ok, so I know how to change XCode build setting to Legacy using the UI shown below.
But how do I build an app from the console using that Legacy setting? I think it has something to do with the command xcodebuild -derivedDataPath <path>. But how do I set it to legacy?
There is no Legacy setting from xcodebuild, although you could use CONFIGURATION_BUILD_DIR to change the default build path:
xcodebuild -project 'MyProject.xcodeproj' \
-configuration 'Release' \
-sdk macosx10.10 CONFIGURATION_BUILD_DIR=/Path/To/Build/Release
If you wanted to build a Debug version just change the configuration flag. If the path is a nonexistent directory xcodebuild should create it automatically.

Can't run Kiwi tests (XCTest) in xcodebuild (Xcode 6)

I'm trying to run my tests using the CLI tools. After following various guides, I came up with this command:
xcodebuild -workspace myworkspace.xcworkspace -scheme testsScheme -sdk iphonesimulator -arch i386 -configuration Debug TEST_AFTER_BUILD=YES clean build
The error I'm getting is:
The following build commands failed:
Ld /Users/<my name>/Library/Developer/Xcode/DerivedData/<project name>-gqrdtdiypfxjrbbjaqofxcjdckcg/Build/Products/Debug-iphonesimulator/<target or schema name>.xctest/<target or schema name> normal i386
I have no idea why the build fails as the error message is not very giving.
As for my pre-configuration, I've followed some guides and did the following: I've added a test-only scheme which targets my tests target (like I've seen in many guides), and also set it's executable to be the .app file (the default settings has no executable which results in an error that the app file is not found).
I'm using Cocoapods, and still not using the standard architecture (arm7, arm64) in my project (I'm dependent on a 3rd party that still hasn't upgraded, so currently my setting is $(ARCHS_STANDARD_32BIT)).
I've also checked that the "${SYSTEM_DEVELOPER_DIR}/Tools/RunUnitTests" run script appears and happens last in the build phases.
Note that running the tests using CMD+U works as intended.
EDIT: Apparently, The .app file wasn't created after a clean (so removing the clean or pre-building the app worked). Nevertheless (even though I need to solve this as well). I'm now getting this error:
PhaseScriptExecution Run\ Script /Users/shay/Library/Developer/Xcode/DerivedData/<name>-gqrdtdiypfxjrbbjaqofxcjdckcg/Build/Intermediates/<name>.build/Debug-iphonesimulator/<test schema>.build/Script-48FB07F617A93C57006E5E2A.sh
I've read that might happen when the iOS simulator is opened, but it happens even if I kill it before running the script.
After sleeping on it, I solved my issue by running:
xcodebuild -workspace <name>.xcworkspace -scheme <scheme> -sdk iphonesimulator -arch i386 -configuration Debug clean build test
Where the scheme is the original one, and not a specially-created one for the tests.

Resources