Error Creating IPA File for Enterprise Distribution: "PackageApplication failed with exit code 1" - iphone

I am running XCode 4.2 and when I Build, Archive, and then attempt to create the IPA file in Organizer, I get the following error message:
PackageApplication failed with exit code 1.
Packaging application: '/Users/Brad/Library/Developer/Xcode/Archives/2011-08-06/*** 8-6-11 4.21 PM.xcarchive/Products/Applications/***.app'
Arguments: embed=/Users/Brad/Library/MobileDevice/Provisioning Profiles/***.mobileprovision verbose=1 output=/var/folders/-K/-K95TJ0AGgaHq4MSn8EjL++++TI/-Tmp-/1376A091-5CA1-4393-AF29-34FFBFD49C74-1082-00000C64DB251DF1/app.ipa sign=iPhone Distribution: ***.
Environment variables:
HOME = /Users/Brad
LOGNAME = Brad
__CF_USER_TEXT_ENCODING = 0x1F5:0:0
DISPLAY = /tmp/launch-r5c1Ou/org.x:0
COMMAND_MODE = unix2003
VERSIONER_PERL_PREFER_32_BIT = no
PATH = /Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin
SHELL = /bin/bash
SSH_AUTH_SOCK = /tmp/launch-SjRZET/Listeners
Apple_PubSub_Socket_Render = /tmp/launch-4KUyaU/Render
TMPDIR = /var/folders/-K/-K95TJ0AGgaHq4MSn8EjL++++TI/-Tmp-/
USER = Brad
VERSIONER_PERL_VERSION = 5.10.0
Output directory: '/var/folders/-K/-K95TJ0AGgaHq4MSn8EjL++++TI/-Tmp-/1376A091-5CA1-4393-AF29-34FFBFD49C74-1082-00000C64DB251DF1/app.ipa'
Temporary Directory: '/var/folders/-K/-K95TJ0AGgaHq4MSn8EjL++++TI/-Tmp-/kNwZk2Uc3U' (will NOT be deleted on exit when verbose set)
+ /bin/cp -Rp /Users/Brad/Library/Developer/Xcode/Archives/2011-08-06/*** 8-6-11 4.21 PM.xcarchive/Products/Applications/***.app /var/folders/-K/-K95TJ0AGgaHq4MSn8EjL++++TI/-Tmp-/kNwZk2Uc3U/Payload
Program /bin/cp returned 0 : []
### Checking original app
+ /usr/bin/codesign --verify -vvvv /Users/Brad/Library/Developer/Xcode/Archives/2011-08-06/*** 8-6-11 4.21 PM.xcarchive/Products/Applications/***.app
Program /usr/bin/codesign returned 0 : [/Users/Brad/Library/Developer/Xcode/Archives/2011-08-06/*** 8-6-11 4.21 PM.xcarchive/Products/Applications/***.app: valid on disk
/Users/Brad/Library/Developer/Xcode/Archives/2011-08-06/*** 8-6-11 4.21 PM.xcarchive/Products/Applications/***.app: satisfies its Designated Requirement
]
Done checking the original app
### Embedding '/Users/Brad/Library/MobileDevice/Provisioning Profiles/***.mobileprovision'
+ /bin/rm -rf /var/folders/-K/-K95TJ0AGgaHq4MSn8EjL++++TI/-Tmp-/kNwZk2Uc3U/Payload/***.app/embedded.mobileprovision
Program /bin/rm returned 0 : []
+ /bin/cp -rp /Users/Brad/Library/MobileDevice/Provisioning Profiles/***.mobileprovision /var/folders/-K/-K95TJ0AGgaHq4MSn8EjL++++TI/-Tmp-/kNwZk2Uc3U/Payload/***.app/embedded.mobileprovision
Program /bin/cp returned 0 : []
+ /usr/bin/codesign -d --entitlements /var/folders/-K/-K95TJ0AGgaHq4MSn8EjL++++TI/-Tmp-/kNwZk2Uc3U/entitlements_rawunFQiwaj /var/folders/-K/-K95TJ0AGgaHq4MSn8EjL++++TI/-Tmp-/kNwZk2Uc3U/Payload/***.app
Program /usr/bin/codesign returned 0 : [Executable=/var/folders/-K/-K95TJ0AGgaHq4MSn8EjL++++TI/-Tmp-/kNwZk2Uc3U/Payload/***.app/***
]
+ /usr/libexec/PlistBuddy -c Set :get-task-allow NO /var/folders/-K/-K95TJ0AGgaHq4MSn8EjL++++TI/-Tmp-/kNwZk2Uc3U/entitlements_plistNowUyBmz
Program /usr/libexec/PlistBuddy returned 0 : []
+ /usr/bin/plutil -lint /var/folders/-K/-K95TJ0AGgaHq4MSn8EjL++++TI/-Tmp-/kNwZk2Uc3U/entitlements_plistNowUyBmz
Program /usr/bin/plutil returned 0 : [/var/folders/-K/-K95TJ0AGgaHq4MSn8EjL++++TI/-Tmp-/kNwZk2Uc3U/entitlements_plistNowUyBmz: OK
]
### Codesigning '/Users/Brad/Library/MobileDevice/Provisioning Profiles/***.mobileprovision' with 'iPhone Distribution: ***.'
+ /usr/bin/codesign --force --preserve-metadata --sign iPhone Distribution: ***. --resource-rules=/var/folders/-K/-K95TJ0AGgaHq4MSn8EjL++++TI/-Tmp-/kNwZk2Uc3U/Payload/***.app/ResourceRules.plist --entitlements /var/folders/-K/-K95TJ0AGgaHq4MSn8EjL++++TI/-Tmp-/kNwZk2Uc3U/entitlements_plistNowUyBmz /var/folders/-K/-K95TJ0AGgaHq4MSn8EjL++++TI/-Tmp-/kNwZk2Uc3U/Payload/***.app
Program /usr/bin/codesign returned 1 : [/var/folders/-K/-K95TJ0AGgaHq4MSn8EjL++++TI/-Tmp-/kNwZk2Uc3U/Payload/***.app: replacing existing signature
codesign_allocate: object: /var/folders/-K/-K95TJ0AGgaHq4MSn8EjL++++TI/-Tmp-/kNwZk2Uc3U/Payload/***.app/*** malformed object (unknown load command 8)
/var/folders/-K/-K95TJ0AGgaHq4MSn8EjL++++TI/-Tmp-/kNwZk2Uc3U/Payload/***.app: object file format invalid or unsuitable
]
error: codesign failed with error 1
Note: I replaced any names with *.

There is no single answer to this problem, partly because Apple's error message(s) is/are not terribly specific.
For my case the solution was this:
Open this Perl script:
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/PackageApplication
and insert this line near the top, like right after the "my $xxxx" declarations:
$ENV{CODESIGN_ALLOCATE} = '/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate';
Credit to http://loopingrecursion.com/index.php?t=codesign for this answer.
The problem seemed to arise after installing some XCode 4.2 beta 7. I eventually uninstalled that one and reinstalled 4.1 from scratch but still couldn't Validate or Share, until I employed this fix.

Ran into this myself a few minutes ago.
Make sure you have a Distribution Certificate in your keychain (you can create one in your Provisioning Portal), and also a Distribution Profile (also you can create this in you Provisioning Portal).
After that, go into your Project properties, to the 'Build Settings' tab.
You'll find a section called 'Code Signing', and at the 'Code Signing Identity' part, at 'Release' you select 'iPhone Distribution'.
That was how i fixed it,
Good luck!
EDIT: just saw you're in the Enterprise program, i'm not sure if my solution works for Enterprise..

The "PackageApplication failed with exit code 1." error during archiving can also be caused by a missing resource. Check your error message for which resource it can't find.

Just to put my 5 cents on this. I had the same error and it turned out that I had 2 Distribution certificates in my keychain. One of them appeared with a red X next to it. After deleting it the error was resolved.

Related

issues with TeamCity, xcrun and single quotes

I'm using TeamCity with xcrun for CI on an IOS project. I'm currently seeing an issues while trying to execute the following command from a TC build step:
-sdk iphoneos PackageApplication "Build/Release-iphoneos/%Product Name%.app" -o "%system.teamcity.build.checkoutDir%/Build/archive.ipa" --sign "iPhone Distribution: AMERICA'S XXXX" --embed "%Provision File%"
The error I get is:
error: /usr/bin/codesign --force
--preserve-metadata=identifier,entitlements,resource-rules --sign "iPhone Distribution: AMERICA'S
--resource-rules=/Library/TeamCity/buildAgent/temp/buildTmp/PotQjg91Ef/Payload/ACCU
Deposit.app/ResourceRules.plist
/Library/TeamCity/buildAgent/temp/buildTmp/PotQjg91Ef/Payload/ACCU
Deposit.app failed with error 1. Output: "iPhone Distribution:
AMERICA'S: no identity found [2013-05-16 14:58:46,533] err -
[2013-05-16 14:58:46,533] out - [2013-05-16 14:58:46,540] out -
Process exited with code 1
I think is pretty clear that the issue is the way xcrun handles single quotes. I tried doubling the single quote to "AMERICA''S" but that didn't work. Can someone help me out? Is there a way to escape single quotes in xcrun?
You need to quote the sign entity iPhone Distribution: AMERICA'S XXXX to make it as only one argument for --sign, otherwise it would be divided by whitespaces and be recognized only the first part. That's what PackageApplication do to recognize command arguments.
I do not know the grammar of your command, but it seems that you should put iPhone Distribution: AMERICA'S XXXX in a variable like %Sign Entity%. Then the whole command should be like this:
-sdk iphoneos PackageApplication "Build/Release-iphoneos/%Product Name%.app" -o "%system.teamcity.build.checkoutDir%/Build/archive.ipa" --sign "%Sign Entity%" --embed "%Provision File%"
Try "iPhone Distribution: AMERICA\'S XXXX".

iPhone Linker error : Command /usr/sbin/chown failed with exit code 1

I am getting a linking error when I try to archive my app. The brief description of the error is
`Command /usr/sbin/chown failed with exit code 1`
The detailed description is
SetOwnerAndGroup "r499908:US-ADdomain" users /Users/r499908/Library/Developer/Xcode/DerivedData/W-akvlnuynzzkjqwcmnnsmrpjpgqfs/ArchiveIntermediates/Advisor/InstallationBuildProductsLocation/Applications/W.app
cd /Users/r499908/Desktop/Projects/JPMorganFunds-Advisor-1.4
setenv PATH "/xcode4-gm/Platforms/iPhoneOS.platform/Developer/usr/bin:/xcode4-gm/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/usr/sbin/chown -RH "r499908:US-AD\\domain users" /Users/r499908/Library/Developer/Xcode/DerivedData/W-akvlnuynzzkjqwcmnnsmrpjpgqfs/ArchiveIntermediates/Advisor/InstallationBuildProductsLocation/Applications/W.app
chown: US-AD\domain users: Invalid argument
Command /usr/sbin/chown failed with exit code 1
Is this because US-AD\domain has a backslash as opposed to front slash? If yes how do I correct this?
The problem was the backslash.
Solved by searching for US-AD\ and changing that to admin
changing install group to admin worked for me

Error when making device build:Command /usr/bin/codesign failed with exit code 1

I am getting this error when making iPad build for device.
"Command /usr/bin/codesign failed with exit code 1"
I searched my blogs and forums and followed steps but no success. Now I deleted all certificate and provisioning profile from keychain and reinstall the latest one but still the same issue. Previously I was using my iOS a/c and now i am using my second iOS A/c certificate. Although when i install the new certificate on another system, it works fine but on my system creating the problem
Please help..
More detail about error...
CodeSign build/Debug-iphoneos/base.app
cd /Users/xx/iPad_work/2011/October/my_test/base
setenv PATH "/Developer/ios_sdk_4.2.1/Platforms/iPhoneOS.platform/Developer/usr/bin:/Developer/ios_sdk_4.2.1/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
setenv _CODESIGN_ALLOCATE_ /Developer/ios_sdk_4.2.1/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate
/usr/bin/codesign -f -s "iPhone Developer: Six sigma (xxxxxxxx)" --resource-rules=/Users/xx/iPad_work/2011/October/my_test/base/build/Debug-iphoneos/base.app/ResourceRules.plist --entitlements /Users/xx/iPad_work/2011/October/my_test/base/build/base.build/Debug-iphoneos/base.build/base.xcent /Users/xx/iPad_work/2011/October/my_test/base/build/Debug-iphoneos/base.app
/Users/xx/iPad_work/2011/October/my_test/base/build/Debug-iphoneos/base.app: object file format invalid or unsuitable
Command /usr/bin/codesign failed with exit code 1
Thanks

object file format invalid or unsuitable Command /usr/bin/codesign failed with exit code 1

i tried running ios 5 on my mac machine along with xcode3.2.4 but after running that(ios 5) if am trying to run my prject in xcode3.2.4 then its thowing this error...
object file format invalid or unsuitable Command /usr/bin/codesign failed with exit code 1
got stuck ..any idea why this is happening?

Code sign exception

I'm trying to upload my iphone application to app store and I followed all the steps that developer program page has in it, and no matter what I change I always get the same exception which is "Command /usr/bin/codesign failed with exit code 1", I'm developing on xcode 4.1, the build log is the next bellow:
CodeSign build/Distribution-iphoneos/xxxx.app
cd /Users/yyyy/Documents/xxxx
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 Distribution: xxxx LLC" --resource- rules=/Users/yyyy/Documents/xxxx/build/Distribution-iphoneos/xxxx.app/ResourceRules.plist -- entitlements /Users/booksprice/Documents/xxxx/build/xxxx.build/Distribution-iphoneos/xxxx.build/xxxx.xcent /Users/yyyy/Documents/xxxx/build/Distribution-iphoneos/xxxx.app
/Users/yyyy/Documents/xxxx/build/Distribution-iphoneos/xxxx.app: The operation was cancelled by the user.
Command /usr/bin/codesign failed with exit code 1
Have you looked at this SO question: codesign "The operation was cancelled by the user" ? Sounds like restarting your Mac and unlocking your keychain helps.
You can develop on Xcode 4, but you should be submitting your application with Xcode 3.2.5.