Cannot build XCode project from command line but can from XCode - iphone

I've created in XCode a simple navigation-based iPhone app. The app builds and runs properly from under XCode but I cannot get it to build from command line.
From terminal I execute:
xcodebuild -project George.xcodeproj -alltargets -parallelizeTargets -configuration Debug build
but I get that error:
=== BUILD NATIVE TARGET George OF PROJECT George WITH CONFIGURATION Debug ===
Check dependencies
[BEROR]Code Sign error: The identity 'iPhone Developer' doesn't match any valid certificate/private key pair in the default keychain
** BUILD FAILED **
The following build commands failed:
Check dependencies
(1 failure)
Is there something wrong with the way I try to handle it?

In addition to unlocking the keychain, you might also specify the codesign identity (or set it in your target). Development certs take the form 'iPhone Developer: Company Inc', distribution certs like this 'iPhone Distribution: Company Inc'.
xcodebuild -project George.xcodeproj -alltargets -parallelizeTargets -configuration Debug build CODE_SIGN_IDENTITY='iPhone Developer: Company Inc'

You can build from the command-line a build targeted at the simulator without signing issues.
This solved the signing issue for me:
xcodebuild -sdk iphonesimulator
Source:
xcodebuild Code Sign error: No matching codesigning identity found:
That's particularly useful if the command line build is there only to sanity check the source code in a continuous integration setup.

Most probably your keychain is locked. Try unlocking it before executing the script, you can do it from command line (right before building):
security unlock -p YourPasswordToKeychain ~/Library/Keychains/login.keychain
Note, I'm using "login" keychain which could be different in your case
Also, if that doesn't help, try removing all other parameters and just leave smth like this:
xcodebuild -configuration Debug and clean beforehand xcodebuild -configuration Debug clean

I'm using shenzhen, it shows this error too.
Turns out, it happens when I plug in my iPad but it is not in the provision profile. By passing --verbose to shenzhen. it shows:
Check dependencies
Code Sign error: No matching provisioning profiles found: None of the valid provisioning profiles include the devices:
XXXX’s iPad
CodeSign error: code signing is required for product type 'Application' in SDK 'iOS 8.3'
unplug the device, everything works just fine...

Depending on the purpose of your script, it may also be sufficient to just turn off code signing in the script, which you can do by setting CODE_SIGN_IDENTITY=''
xcodebuild -project George.xcodeproj -alltargets -parallelizeTargets -configuration Debug build CODE_SIGN_IDENTITY=''
Obviously that's no good if you are trying to do a final build from a script, but it may be fine if you're just trying to do a test build for continuous integration (eg from Jenkins, to make sure that nobody has broken anything).

I had an archiving error similar but not quite the same as the original post:
** ARCHIVE FAILED **
The following build commands failed:
Check dependencies
(1 failure)
This turned out to be a missing Application Service (in my case, the HealthKit service/entitlement), which I had enabled in my development App ID but not my production App ID.
You enable services in the Apple Member Center: https://developer.apple.com/account/ios/identifiers/bundle/bundleList.action

This can be fixed in XCode 8.0 by changing from "iOS Distribution" to "iOS Development" in XCode. It doesn't seem like it should work, but it does for some reason.

Related

Cannot get Ionic 5 to deploy to physical device: Command PhaseScriptExecution failed

I am trying to deploy an Ionic 5 project to an iPhone 12 running iOS 14.6 with XCode 11.4. The app runs fine on the emulator but after following the official instructions here I get Command PhaseScriptExecution failed error and in the logs directly before that is this error:
Code Signing /Users/simonhill/Library/Developer/Xcode/DerivedData/App-buuhfmnvjxqcivakwsfsgrdpsrjw/Build/Products/Debug-iphoneos/App.app/Frameworks/Capacitor.framework with Identity Apple Development: xxx#gmail.com (7FSK2UE87Y)
/usr/bin/codesign --force --sign 7B0B8B04EB8EB60F0EB9540253FEC8FB09E379AC --preserve-metadata=identifier,entitlements '/Users/simonhill/Library/Developer/Xcode/DerivedData/App-buuhfmnvjxqcivakwsfsgrdpsrjw/Build/Products/Debug-iphoneos/App.app/Frameworks/Capacitor.framework'
Warning: unable to build chain to self-signed root for signer "Apple Development: simonhill303#gmail.com (7FSK2UE87Y)"
/Users/simonhill/Library/Developer/Xcode/DerivedData/App-buuhfmnvjxqcivakwsfsgrdpsrjw/Build/Products/Debug-iphoneos/App.app/Frameworks/Capacitor.framework: errSecInternalComponent
I followed the instructions to create my Apple cert and don't understand how to fix this error. I tried this answer Error Xcode 10 . PhaseScriptExecution failed with a nonzero exit code: errSecInternalComponent but could not get it to work.
UPDATE
It may be this problem https://developer.apple.com/support/expiration/:
Known Issues Xcode 11.4.0 and earlier may not be able to sign software
using signing certificates issued by the new Apple Worldwide Developer
Relations Certification Intermediate Certificate. If you’re unable to
upgrade to a supporting version of macOS or Xcode on your build
machine, you can build and archive your app using an earlier Xcode
client and sign it for distribution using the latest release.
Alternatively, you can utilize the codesign tool to sign your software
using the command line.
Definitely seems like this problem: https://developer.apple.com/forums/thread/660087
Updating XCode fixed the problem (12.4).

Swift 5 test build fails with missing Provisioning Profile error

I am trying to build my iOS app from the command line using this command :
$ CODE_SIGNING_ALLOWED=NO xcodebuild -target 'MyApp' -sdk iphoneos -configuration Release
But it fails with the following error :
note: Using new build system
note: Planning build
note: Constructing build description
error: "MyApp" requires a provisioning profile. Select a provisioning profile in the Signing & Capabilities editor. (in target 'MyApp' from project 'MyProject')
Im not interested in signing my app at all. I just want to be able to build from the command line.
Is anyone aware what I am doing wrong?
BTW, I have NOT downloaded any provisioning profile from Apple but Xcode is able to build and run the app. Why is that?

xcodebuild command for Xcode 8 beta to set provisioning profile and team ID

I am not able to build a project from command line in the latest Xcode 8 beta version. Can you please let me know the "xcodebuild" commands for Xcode 8 beta version to build a project through command line. previous commands which we used in previous versions of Xcode does not work now. Every time it throws and error : "Check dependencies
Signing for MyTestApp3 requires a development team. Select a development team in the Target Editor.
Code signing is required for product type 'Application' in SDK 'iOS 10.0'"
Command i used to build - xcodebuild -project MyTestApp3.xcodeproj -sdk iphoneos -configuration Release clean build DEBUG_INFORMATION_FORMAT=dwarf-with-dsym DSTROOT=build GCC_GENERATE_DEBUGGING_SYMBOLS=YES SHARED_PRECOMPS_DIR=build OBJROOT=build SYMROOT=build PROVISIONING_PROFILE_SPECIFIER= CODE_SIGN_IDENTITY="iPhone Distribution: Our Distribution Certificate".
Did you try DEVELOPMENT_TEAM command line parameter?
It can also be set in Xcode (General and Build Settings tabs).
I found the solution by this answer!
Mybe you also want to know how to get the 10-digit team id. Well, I found it in the output of command
xcodebuild -showBuildSettings -project <YourProject> |grep DEVELOPMENT_TEAM

iPhone codesign error (ResourceRules.plist: cannot read resources) when attempting to share app

I'm attempting to share my app ad hoc. I can build and run it on my device but when I archive it and attempt to share it I get a strange error I've never seen before, see below. Any suggestions?
error: /usr/bin/codesign --force --preserve-metadata --sign iPhone Distribution: Joe Blogs--resource-rules=/var/folders/7z/gv6v8fqx737d6k1sytnchgrh0000gn/T/0ePfwPLHPA/Payload/My App.app/ResourceRules.plist --entitlements /var/folders/7z/gv6v8fqx737d6k1sytnchgrh0000gn/T/0ePfwPLHPA/entitlements_plistd2eAQQ_S /var/folders/7z/gv6v8fqx737d6k1sytnchgrh0000gn/T/0ePfwPLHPA/Payload/My App.app failed with error 1. Output: /var/folders/7z/gv6v8fqx737d6k1sytnchgrh0000gn/T/0ePfwPLHPA/Payload/My App.app/ResourceRules.plist: cannot read resources
The app you're trying to build is probably invalid. Are you sure you're building against the iphoneos SDK and not the simulator SDK ?
Can you provide the xcodebuild command that produced your .app file

Build fail error

I am baffled about this error since I installed xcode 4.2 from xcode 3.2 and switched back to xcode 3.2 Since then I am not able to build for device for any of my projects for any configurations.
The error shown is:
CodeSign build/Debug-iphoneos/MyProject.app cd
"/Users/macadmin/Documents/iPhoneProjectDocs/Madhup/Test/Test
Development/MyProject" setenv PATH
"/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
setenv _CODESIGN_ALLOCATE_
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate
/usr/bin/codesign -f -s "iPhone Developer: Madhup (MW9495NA8W)"
"--resource-rules=/Users/macadmin/Documents/iPhoneProjectDocs/Madhup/Test/Test
Development/MyProject/build/Debug-iphoneos/MyProject.app/ResourceRules.plist"
--entitlements "/Users/macadmin/Documents/iPhoneProjectDocs/Madhup/Test/Test
Development/MyProject/build/MyProject.build/Debug-iphoneos/MyProject.build/MyProject.xcent"
"/Users/macadmin/Documents/iPhoneProjectDocs/Madhup/Test/Test
Development/MyProject/build/Debug-iphoneos/MyProject.app"
/Users/macadmin/Documents/iPhoneProjectDocs/Madhup/Test/Test
Development/MyProject/build/Debug-iphoneos/MyProject.app: object
file format invalid or unsuitable Command /usr/bin/codesign failed
with exit code 1
The things I have tried to get over this are:
Completely removed all provisioning profiles and certificates and re-install them.
Change configurations (Debug to some other)
Completely uninstall and re-install xcode
Moreover if I try to build my project from some other systems with same provisioning profile, developer certificate and same build configuration I don't face any problem.
Please help me out as I am so frustrated and thinking of OS re-install :(
So to clarify, you've removed xcode with...
sudo /Developer/Library/uninstall-devtools –mode=all
Have you also cleaned the build (Product menu -> Clean)? I know this sounds a bit of an obvious one - but lots of people forget to do it!