Monday, November 7, 2011

code sign failed exit code 1

Say what?  That's what I thought anyway.

I encountered this error when creating an iOS application for the iPhone.  It seems everyone is doing it these days, and we had a unique need to get something to market so I thought why not.  I fired up an Intel-based Mac book Pro, obtained the $99 for developer account, and downloaded XCode 4.2.  So armed with Google and an entry-level text book, I was off and running.

The app I was coding was a very basic app, I'll admit that.  Its not fancy at all and quite text-book in nature, so I was confident I could build it to run on the older iPhone 3g without problems.  However I learned that, starting with XCode 4, Apple is trying to nudge developers to code for the newer iPhone 4 platforms by defaulting the architecture to "armv7" only.  To build support for the older iPhone 3g, for example, you need to specifically add in support for the "armv6" architecture.

Within the project's Build Settings, in XCode 4.2, the Architectures value defaults to $(ARCHS_STANDARD_32_BIT), which will produce only a "armv7" build.  In order to add support for armv6, you must change a few values in the Build Settings:
  • Remove $(ARCHS_STANDARD_32_BIT) from Architectures and replace with "armv6 armv7"
  • Set Build Active Architecture Only to "No"
  • Change Valid Architectures to "armv6 armv7"
Somewhere along the way through my Google adventures, I found a suggestion that indicated I also needed to set the Build Variants to "armv6 armv7" as well.  It turns out, this is where I went wrong.  This value NEEDS to be set to "normal" or one of the other two acceptable values (See reference here).  And believe it or not, if you set this to an invalid value, the only way you will know is when you try to code sign your project during testing, and receive an error like this:
/Users/itguy/Library/Developer/Xcode/DerivedData/BoyneResorts-fnonapqepzdshocfykqbsfmoqugh/Build/Products/Debug-iphoneos/BoyneResorts.app: object file format unrecognized, invalid, or unsuitable
Command /usr/bin/codesign failed with exit code 1
As a result, I have come to believe that a large part of being a software developer is simply having the ability to interpret a very cryptic nondescript error to find the solution to a problem in a seemingly unrelated area of your code or project.

During my experiences building my first iPhone app I also came across  a few other links that I found very helpful.  First is the Technical Note TN2250 from Apple that steps you through the code signing process.  Second is a blog entry over at OopsTechBlog.com which I stumbled upon through my Google searches that condenses all the image sizes and requirements in a nice neat table; very helpful.

2 comments:

  1. Have been trying to get around the 'format unrecognized, invalid, or unsuitable' build failure issue for a few hours now. After reading this I changed BUILD_VARIANTS (in the Build Options section of the Targets Build Settings) to normal. It now builds and I can run on real devices (was able to run under the simulator without making this change).

    Note that 'normal' should NOT be capitalized as shown above (I first tried with Normal and it failed). The reference link above shows normal as all lower case.

    Thanks for the post!

    ReplyDelete
  2. Thanks for the heads-up! I updated the original post so it won't trip up anyone else

    ReplyDelete