How is code signing done in Xcode 4.5 - ios

I have a script for building my app that is broken since updating to Xcode 4.5. The problem is code signing. When I run the following:
/usr/bin/xcrun \
-sdk iphoneos \
PackageApplication \
-v "${BUILD_DIR}/${APPLICATION_NAME}.app" \
-o "${APP_ARCHIVE}" \
--sign "${DEVELOPER_ID}"
--embed "${PROVISIONING_PROFILE}"
I get the following error:
error: /usr/bin/codesign --force --preserve-metadata --sign iPhone Developer: Apple Developer --resource-rules=/var/folders/p5/gfgpv6911ylbs52cnbh2___m0000gq/T/ky9_XtRlRr/Payload/Blah.app/ResourceRules.plist /var/folders/p5/gfgpv6911ylbs52cnbh2___m0000gq/T/ky9_XtRlRr/Payload/Blah.app failed with error 1. Output: /var/folders/p5/gfgpv6911ylbs52cnbh2___m0000gq/T/ky9_XtRlRr/Payload/Blah.app: replacing existing signature
codesign_allocate: object: /private/var/folders/p5/gfgpv6911ylbs52cnbh2___m0000gq/T/ky9_XtRlRr/Payload/Blah.app/Blah malformed object (unknown load command 34)
/var/folders/p5/gfgpv6911ylbs52cnbh2___m0000gq/T/ky9_XtRlRr/Payload/Blah.app: object file format unrecognized, invalid, or unsuitable
Something is going wrong with the code signing where it was working fine with Xcode 4.3 before. Can code signing still be done with the same command? Is this "unknown load command" the culprit, and if so, what is it, and how would one go about finding and fixing it?

It turns out upgrading XCode from App Store does NOT automatically upgrade everything.
Go to Preferences / Downloads and make sure the latest Command Line Tools are installed.

And once you update the cmd restart your mac for better results, I wasted 1 hour on this.

Related

Embedding framework in iOS generates an error when signing

I am currently trying to embed the Azure client framework into an iOS project, but the build is failing when it tries to sign the framework, with the following error:
~/Library/Developer/Xcode/DerivedData/MyProject-gtoxtgdnkyheledfgmjhogvasnql/Build/Products/Debug-iphonesimulator/MyProject.app/Frameworks/AZSClient.framework: bundle format unrecognized, invalid, or unsuitable
After poking around on the web, I found this highly useful page:
https://github.com/mattgallagher/CwlSignal/issues/16
The command being run by code sign is this:
/usr/bin/codesign --force --sign - --timestamp=none \
--preserve-metadata=identifier,entitlements,flags \
~/Library/Developer/Xcode/DerivedData/MyProject-gtoxtgdnkyheledfgmjhogvasnql/Build/Products/Debug-iphonesimulator/MyProject.app/Frameworks/AZSClient.framework
which generates the error I mentioned above. Following Mat's lead and modifying the end of the command to point to the actual framework binary as follows:
/usr/bin/codesign --force --sign - --timestamp=none \
--preserve-metadata=identifier,entitlements,flags \
~/Library/Developer/Xcode/DerivedData/MyProject-gtoxtgdnkyheledfgmjhogvasnql/Build/Products/Debug-iphonesimulator/MyProject.app/Frameworks/AZSClient.framework/AZSClient
the command correctly executes and signs the framework.
My Question:
How do I modify the Xcode build system to do this. If I try just building after running the code sign on the command line, it overwrites my code sign. If I try building without signing the framework, it presents an unsigned version of the framework to the target (in this case the simulator).

Xcode build error "Command /usr/bin/codesign failed with exit code 1" in simulator and real environment

I recently created a new project. It was 8 months ago when I created the project last time. So, when I built a new project with simulator, I got an error like the following.
CodeSign {app directory}
cd {app directory}
export CODESIGN_ALLOCATE=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/codesign_allocate
export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
Signing Identity: "-"
/usr/bin/codesign --force --sign - --entitlements /Users/{username}/Library/Developer/Xcode/DerivedData/{app directory}
/Users/{username}/Library/Developer/Xcode/DerivedData/{app directory}/{app name}: Is a directory
Command /usr/bin/codesign failed with exit code 1
I tried
Confirm Xcode sign-in status
Check Automatically manage signing
Clean up and delete build DerivedData
Reboot Xcode and PC
Reinstall Podfile and cocoapod
Recreate certificate
xattr -c
I tried several method. But it did not solve it.
Most people seem to be OK in a simulation environment, but in my case it is not. Both the real environment and the simulation will not work.
Thank you.
The error is there in the output from the command:
/Users/{username}/Library/Developer/Xcode/DerivedData/{app directory}/{app name}: Is a directory
You most likely have some custom build phase or script phase which is stomping over your app's executable with a directory.

Codesign fails during xcodebuild archive in Bamboo only

I have a script that builds and archives an iOS App using xcodebuild. Running it manually on the CI server works perfectly, but it always fails if run as a task in Bamboo:
/Users/bamboo/Library/Developer/Xcode/DerivedData/MyApp-fznnexbqdbnwoebohwwvajvtmcdf/Build/Intermediates/ArchiveIntermediates/LIVE/InstallationBuildProductsLocation/Applications/MyApp.app: unknown error -1=ffffffffffffffff
Command /usr/bin/codesign failed with exit code 1
** ARCHIVE FAILED **
the archive command looks like this:
xcodebuild -workspace "${workspace}" -scheme "${scheme}" -archivePath "${archive_path}" clean archive
I did try:
using security unlock-keychain before the xcodebuild command
chaining security unlock-keychain and xcodebuild commands with &&
manually unlocking keychain
moving the signing certificate and key to System keychain
setting Allow all applications to access this item in keychain
searching SO and everything else (even asking the janitor :) )
If this is of any help, the project uses manual signing, the profile and certificate are specified in build settings because those change quite often, nevertheless the logs show that the right signing identity is picked up.
Any suggestions of what could be wrong are welcome.
Open Terminal and paste this two:
cd ~/Library/Developer/Xcode/DerivedData
xattr -rc .

Xcode5.1 xcrun: error: unable to find utility "PackageApplication", not a developer tool or in PATH

After installing Xcode5.1 with iPhone7.1 sdk I am getting the following error when trying to package my application in the command line:
xcodebuild: error: SDK "iPhoneOS7.1.sdk" cannot be located.
xcrun: error: unable to find utility "PackageApplication", not a developer tool or in PATH
I have already installed Xcode command line tools in previous version of Xcode and the upgrade to Xcode5.1 did not remove them. The option to install "command line tools" is not available in Xcode preferences/downloads.
Any ideas how to fix this error?
I got this error when using Carthage. It happened because I first installed the commandline tools, and only afterwards, the full Xcode application. To fix this, I had to run the following command:
$ sudo xcode-select --reset
Right, so after a short trial and error loop I figured it out: I was calling xcrun with an sdk name it does not recognize:
xcrun -sdk iPhoneOS7.1.sdk PackageApplication -v appName.app -o appName.ipa
The correct syntax which worked for me is:
xcrun -sdk iphoneos PackageApplication -v appName.app -o appName.ipa
I found how to automate the build and archive process from the command line, I just find a blog article explaining how you can achieve that.
The command you have to use is xcrun:
/usr/bin/xcrun -sdk iphoneos PackageApplication -v "${RELEASE_BUILDDIR}/${APPLICATION_NAME}.app" -o "${BUILD_HISTORY_DIR}/${APPLICATION_NAME}.ipa" --sign "${DEVELOPER_NAME}" --embed "${PROVISONING_PROFILE}"
You will find all the details in the article. If you have any questions dont hesitate to ask there.
Hope this will help you out.
After Xcode 8.x,Apple remove PackageApplication ,so ,you should download PackageApplication to the specified dir. The dir is :/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin
Then you should query and download PackageApplication. github: https://github.com/JackSteven/PackageApplication

xcrun error: Failed to read entitlements from

So im trying to automate the build and archive process through a script. In my script, I run the xcodebuild script and that builds fine. Then I try to run the xcrun
/usr/bin/xcrun -sdk iphoneos PackageApplication "path_to_.app" -o "output_path" --sign "devname" --embed "provnprofile"
However I get this error:
error: Failed to read entitlements from '/var/folders/U5/U5q0xqZRG6SrO8AMQkMjeE+++TM/-Tmp-/fIcrdMUa76/Payload/MyApp.app'
Anyone have any ideas why?
Thanks in advance
I just encountered the same issue. It was actually related to my .app folder generated with xcodebuild which wasn't successfully built.
Try to use xcodebuild with the verbose (-verbose) enabled and check the stack trace.
I hope it will help.
double check the package you are building in Xcode. Very often, a project has multiple packages and targets to build. You might have selected a distribution package or not the one you intent to build.

Resources