38

I accidentally deleted my target in xcode.

so i created a new one with the exact same name. in the target settings i again selected the proper codesigning identity

but now i can't compile for the device anymore. as soon as i want to build, i get:

CodeSign build/Release-iphoneos/myApp.app
....somestuff....
/Volumes/XCodeProj/myApp/build/Release-iphoneos/myApp.app: object file format invalid or unsuitable
Connad /usr/bin/codesign failed with exit code 1

I already tried to clean targets. what could cause this problem and how to solve it?

Mat
  • 505
  • 1
  • 5
  • 7

17 Answers17

78

May also be an issue with your install. Symlinking to the latest codesign_allocate cleared up the issue in my case:

sudo mv /usr/bin/codesign_allocate /usr/bin/codesign_allocate_old
sudo ln -s /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate /usr/bin
Ed McManus
  • 7,088
  • 2
  • 25
  • 17
  • That was my case. Thank you!! – M Penades Sep 13 '11 at 15:56
  • 4
    +1. Same issue here, only the 4.1 installation didn't install a codesign_allocate whatsoever. While I have both the iOS 5 beta (different dir), I did install the 4.1 SL install most recently. xcode-select also still shows "/Developer". So the symlink alone for me did the trick. Thanks emcmanus. – Scott Corscadden Sep 20 '11 at 01:10
  • installed 4.2 and uninstalled it. installed 4.02 again, had the problem and solved it with the suggested method – eugene Nov 11 '11 at 07:41
  • 2
    I didn't have a /usr/bin/codesign_allocate. But I did have the same error as op. Creating the symlink (your 2nd step) fixed it. – August Lilleaas Nov 30 '11 at 14:21
  • That was incredible! I had updated to whatever the new XCode for iOS 5 is, and then decided to backdate because I wanted to release my app for iOS 4 (not to mention the new XCode was not working very well). I was unable to build, and the second line of code did the trick. Thanks! – WolfLink Dec 05 '11 at 06:55
  • 1
    In my case, /usr/bin/codesign_allocate was lost and I could recover it by ln command only. Thanks. – conecon Jan 11 '12 at 09:31
  • 3
    Had this problem trying to compile my Mac OS X app for the 10.8 GM as well.Didn't have /usr/bin/codesign_allocate. Linked it from the iPhoneOS.platform directory as per emcmanus suggestion (but mine is found inside /Applications/Xcode44-DP7.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate), and it worked like a charm. – junjie Jul 10 '12 at 06:50
  • Had this problem on OSX 10.8 and Xcode 4.4 due to the fact that /Developer folder is moved i used following commands to fix that: sudo mv /usr/bin/codesign_allocate /usr/bin/codesign_allocate_old sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate /usr/bin – BamboOS Jul 27 '12 at 11:24
  • 2
    I just updated my mac mini to mountain lion and the second line was enough to get the code signing to work again. thanks! – user574771 Aug 16 '12 at 03:53
  • Just the last line did trick for me. Thank you so much emcmanus. – Mohan Nov 14 '12 at 11:57
  • 1
    If you don't want to symlink by hand, simply installing the Xcode CommandLine tools from the Xcode preferences fixed it for me. – Johannes Rudolph Apr 15 '13 at 12:46
  • MY HERO! I also had to restart Xcode but nevertheless, it works! Thank you! – jsetting32 Jun 24 '15 at 20:22
  • Thanks! In my case, gcc5 was generating instructions that 10.6 Snow Leopard's codesign_allocate couldn't understand, so I did: `sudo mv /usr/bin/codesign_allocate /usr/bin/codesign_allocate_apple` then `sudo ln -s /opt/local/bin/codesign_allocate /usr/bin/codesign_allocate` to activate the newer MacPorts codesign_allocate. Worked like a charm. – Raptor007 May 11 '16 at 01:35
  • Thanks ! after a fresh new install of the good old XCode 3.2.6, it refuse to codesign apps. It was just because codesign_allocate wasn't present in usr/bin on the system. Just copy from developer/platforms/... and it works ! – Chrysotribax Mar 07 '17 at 11:24
52

In Mountain Lion, you can try to run this before codesign:

export CODESIGN_ALLOCATE="/Applications/Xcode.app/Contents/Developer/usr/bin/codesign_allocate"
Marius
  • 3,589
  • 3
  • 27
  • 30
  • 1
    Fixed the problem on Mountain Lion for me too. – Levi Nunnink Jul 31 '12 at 05:48
  • 1
    +1 This worked for me too. The app is being built by Jenkins CI server and it suddenly stopped working (not sure why, I'll have to investigate), but I updated the build script with this line and it worked. – Sam Jun 14 '13 at 08:43
42

Make sure the 'Executable Name' (CFBundleExecutable) entry in your target's info.plist matches the 'Product Name' specified in your target settings.

Julio Gorgé
  • 10,056
  • 2
  • 45
  • 60
  • This is what did it for me. Any idea why these need to be the same? – rykardo Jan 14 '12 at 07:06
  • This did it for me too. Other apps build fine, so it had to be something about this one project. Strange; I messed my project after duplicating a target (developing "part 2" of an app). I even made a new workspace & project and imported all the files again, but didn't work. This solved it (Xcode 4). – Nicolas Miari Apr 05 '12 at 11:56
10

I had this issue when I was trying to codesign from the terminal. I had just installed Xcode 4.4 after uninstalling Xcode 3.0. Took a look at the Downloads in Xcode preferences and noticed that the Command Line Tools had not been installed. My issue was fixed after I installed this. I'm guessing the problem is more complex given the solutions here, but this might be something that future users want to check before they have to start diving deeper.

Jeff Blenman
  • 101
  • 1
  • 4
7

For me, this was occurring after upgrading to XCode 4.5.

The solution was simply to go to Preferences / Downloads and install the latest Command Line Tools.

Ville Laurikari
  • 28,380
  • 7
  • 60
  • 55
4

I had the same problem and tried all sorts of build settings GCC4.0, search paths etc etc. It turned out to be nothing to do with the build settings in my case the problem was I put a dot in the target name i.e. I was targeting v3.0 SDK so I called the target Granade3.0.

I started a brand new project named "Grenade3zero", imported the sources from the original, fixed the appdelegate name to match the project name etc. build and go and it loaded first time onto the device and the simulator was also fine when I checked it. Looks like some characters are illegal in target names!

Soft Dot IE
  • 141
  • 4
  • You can also just rename the product in the build settings and rename the delegate class. Or, in Xcode, go to Project -> Rename Project… –  Jan 30 '11 at 22:17
  • Thanks Radek, I agree renaming would work but restarting using a valid project template seems to have fixed suspect dubious build settings – Soft Dot IE Jan 31 '11 at 16:06
  • Happened again after I provisioned with a new keychain, old keychain was visible to xcode and EMcManus's solution sorted the duplicate problem. I then got an invalid object file problem which turned out to be my IPod Device OS was 4.2.1 and I had to target a base sdk in the target settings to the highest version below that - in my case 3.2.1. – Soft Dot IE Feb 21 '12 at 22:18
4

Thought I'd add my solution to this problem too... I've been struggling for a couple of weeks with this problem... having checked ALL the solutions above and changing more.

My solution was in the target build settings.

I had put in two options, armv6 and armv7. I changed this back to one single entry of normal and it built!

build settings

Matt Facer
  • 3,103
  • 11
  • 49
  • 91
  • I tried both emcmanus's and Julio's suggestions and both didn't work for me. But, your's did. Thanks! – Daren Jan 14 '12 at 22:55
3

emcmanus answer worked for me but since Xcode 4.3 is now installed in the Applications folder and I removed the old /Developer folder, I had to change the path to codesign_allocate:

sudo mv /usr/bin/codesign_allocate /usr/bin/codesign_allocate_old
sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate /usr/bin
massimobio
  • 808
  • 9
  • 11
2

I tried all the above to no avail. What worked for me was to add the following to my build script:

export CODESIGN_ALLOCATE="/Applications/Xcode.app/Contents/Developer/usr/bin/codesign_allocate"

I came across this post while researching my problem: http://mobiledevelopertips.com/mac-osx/code-signing-error-object-file-format-unrecognized-invalid-or-unsuitable.html

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
2

For Mountain Lion before starting signing process Please run below command as first command.

For Xcode 4.x: export CODESIGN_ALLOCATE="/Applications/Xcode.app/Contents/Developer/usr/bin/codesign_allocate"

For XCode 5: export CODESIGN_ALLOCATE="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/codesign_allocate"

Meet
  • 4,904
  • 3
  • 24
  • 39
1

Faced a similar issue in Jenkins running on Mountain Lion and Xcode 5.x.x without any command line utilities. since the command line utilities are now bundled with Xcode 5.1.x

the following worked

sudo ln -s /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/codesign_allocate /usr/bin/

bhuvan
  • 56
  • 2
1
  1. Go to 'Build Settings'
  2. Go to 'Build Options' tab
  3. Inside of the build options tab go find 'Debug Information Format' and change it's value from 'DWARF' to 'DWARF with dSYM File'. Should be in the dropdown.

It should work for you guys.

0

I think that it was cause by one of Xcode DP(developer preview). It could change default Xcode.app Path to Xcode DP.

So, U can check Xcode path by xcode-select --print-path

If U got some wrong directory then U could change path by xcode-select --switch

check this thread. change xcrun developer path

Community
  • 1
  • 1
TopChul
  • 419
  • 2
  • 14
0

It is better to use xcrun to locate the correct version of codesign_allocate as it can be different depending on whether it is an OS X binary or iOS.

This also allows Apple to change the location of various tools without breaking your script.

Use something like:

export CODESIGN_ALLOCATE=$(xcrun --sdk iphoneos --find codesign_allocate)

oenpelli
  • 3,467
  • 2
  • 29
  • 20
0

I would get the error when trying to sign my OS/X (not iOS) application with a digital certificate my company purchased from a root Certification Authority different from Apple. The problem would occur whenever I downloaded the certificate via Safari. Downloading the certificate using Firefox helped me get rid of the error.

Flying Island
  • 61
  • 1
  • 3
  • @kjhughes, you might have not made it all the way through the post, but it is indeed an answer, not a question. – Mike Sep 05 '14 at 21:01
0

If your app has special characters in the Product Name in the target build settings, remove them.

For example, rename "Mat's app" to "Mats app" and it will build. You can of course have special characters in the display name.

Dimitris
  • 13,480
  • 17
  • 74
  • 94
0

I also had the same problem, and the cause was that my app target was linked to a static library and didn't provide its own source files (all sources were in the library and the app target only provided resources). Once I moved out one of the sources from the library to the app target, it fixed the code sign error.

Avi
  • 826
  • 6
  • 16
  • Please give ans in some good format not just para of text do some bold text for highlighting the valuable info and like that – The iOSDev Oct 28 '12 at 06:37