63

I have the following error:

Command /usr/bin/codesign failed with exit code 1

Here is what I already did for trying to fix this:

  • set the bundle identifier to com.server.pgmname
  • set the code signing to "Any Iphone OS Device"
  • set the Code Signing Identity to my Distribution identity.

The error only occurs when I try to build on my device, on the simulator everything works fine.

Do you have any suggestions?

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
Daniel
  • 1,179
  • 4
  • 18
  • 31
  • 1
    You can always build on the Simulator, no certificates needed for that. Btw, what kind of build are you doing? Debug/Ad-Hoc/Distribution> – Anurag Jan 07 '10 at 02:10
  • Any errors showing up in logs? (Console.app) – Peter Loron Jan 07 '10 at 03:18
  • 1
    This may seem like an obvious question, but do you have a provisioning profile installed with the correct bundle identifier or a wildcard profile? Is the provisioning profile actually a Distribution profile and not a Development profile? If Distribution, is it an app store profile or ad-hoc? Note that for distribution you're going to need an appropriate Entitlements.plist file configured or it won't install. – Nimrod Jan 07 '10 at 04:08
  • No, no errors in the logs. Actually all I want to do is creating the final version to put it on the app store. So I think it should be the distribution.. or maybe the release!? Sorry.. I'm pretty new to this and it's my first time... @Nimrod: I have a provisioning profile installed with the proper bundle identifier set. The Distribution is an App Store profile. Actually I have one distribution profile and one provisioning profile..both set up at the provisioning tab at the itunes connect menu... And last answer: yes I even have a Entitlements.plist file... – Daniel Jan 07 '10 at 13:03
  • Closed! I just created a new project, copied all my calsses and resources and then it worked! – Daniel Jan 07 '10 at 23:27
  • @daniel that only worked a few hours then it stopped again. There is a bug here with Xcode -but I have no idea how to replicate it simply.. – UKDataGeek Dec 25 '16 at 22:38
  • 33 answers. thank you apple –  Feb 15 '18 at 08:30

43 Answers43

61

I had the exact same error, and tried everything under the sun, including what was suggested elsewhere on this page. What the problem was for me was that in Keychain Access, the actual Apple WWDR certificate was marked as "Always Trust". It needed to be "System Defaults". That goes for your Development and Distribution certificates, too. If any of them are incorrectly set to "Always Trust", that can apparently cause this problem.

So, in Keychain Access, click on the Apple Worldwide Developer Relations Certificate Authority certificate, select Get Info. Then, expand the Trust settings, and for the combo box for "When using this certificate:", choose "System Defaults".


Sigh: for those insistent on downvoting this answer, I am not claiming this to be the only solution for this problem. It's one solution. It may not work for you. There are multiple reasons for this codesign failure.

Nate
  • 31,017
  • 13
  • 83
  • 207
  • Thank you so much, driving me crazy. this fixed it – Phill Pafford May 29 '12 at 03:12
  • 112
    You're welcome, @Phil. This is the kind of problem that causes me to consider giving up programming, to live a nomadic life of collecting berries, hunting squirrels, and never touching a computer again ... – Nate May 29 '12 at 04:45
  • @Nate wow thanks mate, that was the problem... :) just brilliant. – Jorge Y. C. Rodriguez Jun 16 '13 at 14:01
  • 14
    am I the only one who followed these steps without success? (actually System Defaults was already set ) – Stas Oct 15 '14 at 13:13
  • @Stas, surely, this is not the only solution that will remedy problems showing this error code. You might try the other ones, too. I've also provided this answer multiple times on Stack Overflow, so you might try searching for other questions with the same error message. Good luck. – Nate Oct 16 '14 at 01:56
  • For me too System Defaults was already set, I am still having the issue. No idea why this is happening in one project only. – Michel Dec 06 '15 at 02:56
  • 2
    Mine `When using this certificate` was already set to `System Defaults` even though XCode used to show *error*. If you are runnin **El Capitan** then select `Always Trust`, this fixed error for me. – Apurva Jun 09 '16 at 12:27
  • In my case, I simply didn't have the bloody thing. Bummer. – Florin Odagiu Nov 07 '16 at 13:13
  • Have you got any other solutions. It is not working for me. :( – Vineesh TP Apr 10 '17 at 09:35
  • 2
    @Nate Apple just makes people feel that way. – DenLilleMand Dec 06 '17 at 09:56
  • It worked!WTF MAN! How system def is a fix than Always accept? THAT MAKES NO SENSE – Kohls Mar 26 '20 at 17:27
31

I had the exact same problem and this did the trick for me:

Xcode > Preferences > Accounts > View Details > And just refresh the Provisioning Profile

Seems like the accounts in Xcode were not updated with the latest provisioning profiles so a quick refresh sorted this out.

mgm
  • 1,298
  • 14
  • 16
29

Feel the need to share this, even though it's ridiculous.

I'd set up a second developer account on my Mac and couldn't codesign anything. The error was "the user cancelled the operation".

A simple reboot fixed this for me.

Chris Newman
  • 2,240
  • 2
  • 24
  • 30
  • 2
    Reboot did work for me too. I have no idea why, but thank you anyway. – kufi Jan 31 '14 at 10:17
  • I'll give it a try, but then I cant vote up for this answer. – pkarc Oct 29 '15 at 21:01
  • 1
    I tried everything, refusing to believe that a reboot would fix it, but it did! Feels like a Windows 95 solution. – mvandillen Feb 16 '18 at 09:08
  • Try this first. If this works then no need to try everything else. – Skywalker Mar 06 '18 at 04:36
  • THANK YOU, this worked for me. The codesign issue went away after fixing AppleID session issue (following MGM's answer) and then rebooting. From Xcode 9.3 – user3064009 Apr 10 '18 at 23:13
  • Stuff like this drives me batty, but yes, after tinkering with way too many issues after simply renaming a project, wasting hours, one darn reboot fixes the last remaining odd code signing issue related to the Bolts framework. – drew.. May 14 '18 at 13:47
11

I was fighting for about 2-3 hours to codesign a project with Parse API. It turned out that the embedded frameworks caused the problem. Make sure you set "Code sign on copy" (see picture). If does not work delete the Parse and Bolts frameworks from the list and remove them from your project then add them again.

enter image description here

Teddy
  • 1,056
  • 1
  • 14
  • 24
10

What worked for me was to realize that Xcode did not have access to the certificates. Please check that your certs are accessible by Xcode. Go to Keychain Access -> Certificates -> Open the Cert and double click on the private key -> Select Access Control

enter image description here

yairsz
  • 438
  • 5
  • 15
Mat Zero
  • 386
  • 3
  • 9
9

Just troubleshooted this same issue. I'd created a resources folder with my icons inside, then added it to my project via right-click > Add Files > [select resources folder]. Apparently this is a bad idea.

Instead create a new group in your project (called "Resources" in my case), and then right click > add files to that and then choose the individual files. Project built immediately.

Psiloc
  • 257
  • 3
  • 9
5

For me, I just updated to Xcode 8, and converted my Swift 2.2 code to Swift 3 code, and I got errors in the Unit Testing and UI Testing. I just cleaned and then all the errors disappeared.

Ace
  • 51
  • 1
  • 2
3

For anyone with this problem in the future (who doesn't want to rebuild their project), an additional question to ask is whether you have a space in your product name. I'd recommend going through your properties (right-click -> get info) of your project and your target. For my project, the only place that a space was needed was in the plist for the bundle display name.

umop
  • 2,122
  • 2
  • 18
  • 22
3

Very often the error /usr/bin/codesign failed with exit code 1 occurred in case the user has no file extensions for texture files in Models.scnassets folder. macOS very often generates a files with hidden extensions.

For example: you have a file myTexture but it must include an extension as well – myTexture.png.

Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
3

After hours of googling and trying out different things, this is what fixed it for me:

  1. Make sure there are no certificates in the System > Certificates tab on Keychain Access. Remove all duplicate certificates from there.

  2. Install the WWDR intermediate certificate under certificates from the provisioning portal, in addition to the developers certificates and make sure you see it in the Login > Certificates tab on Keychain Access.

j0k
  • 22,600
  • 28
  • 79
  • 90
a_s_
  • 41
  • 2
2

I got this error the very first time I tried to make a provisioning profile by following the Provisioning Assistant and it turns out they fail to mention the WWDR Intermediate Certificate. I installed it and it worked fine for me.

Ben Aubin
  • 5,542
  • 2
  • 34
  • 54
mnen
  • 33
  • 8
2

I had this same problem and couldn't figure it out for a long time. I tried everything on this page and others and it still didn't work. But eventually, I did find a fix.

For this to work, make sure Xcode is not running. After you've closed Xcode, open Terminal and type in the command:

xattr -rc /[The File Directory of your project found in the File Inspector of your .xcodeproj file in Xcode]/

Obviously don't put the text in brackets, just replace it with what it says. Hit enter. Don't worry if nothing shows up below the command, it didn't for me. After that, you can close out of Terminal and open Xcode. Now everything should be fine. Note: It might take a little longer to run your project, but just wait it out.

Also note: Don't downvote this answer because it doesn't work. This is one way to fix it that worked for me, but it might not work for you because you might have something else that is broken.

Adalex3
  • 400
  • 4
  • 14
2

Here is my way to resolve:

  • Open keychain access, select your iOS certificate, Delete private key
  • Then go back to xCode, you will see warning warning message and "Revoke" button, click it and error resolved.
Duy Chung
  • 122
  • 7
1

In my case, I had an extra expired distribution certificate in my keychain - I deleted the certificate from KeyChain Access and the compilation started working again.

Zorayr
  • 23,770
  • 8
  • 136
  • 129
1

If you're using phonegap/cordova:

I got this when building from Cordova but the solution for me was much simpler. A permissions issue.

Just set the files to correct permissions

chmod -R 774 ./projectfolder

And then set ownership

chown -R youraccname:staff ./projectfolder 
el_nariz
  • 259
  • 4
  • 15
1

Some of the answers above allude to the problem but don't clearly spell out the steps to correct it.

Here is my attempt at after it has become super frustrating which seems to have worked for me so far :

The problem is caused because there is duplicate certificates in your Apple Developer portal or potentially in your machine. I haven't had any negative consequences from doing this and its worked so far.

  1. Close Xcode!

  2. You have to remove the existing certs from your developer account visit : https://developer.apple.com/account/ios/certificate/development/ and select development account ( there should be multiple certs) I revoked each one by clicking on them and selecting revoke.

select development certs

2.remove certs from your keychain on your Mac

  • Open Keychain app by pressing clover+space and typing in keychaing
    and pressing enter
  • Search in the top right hand corner for "developer"
  • Select the potential duplicate keys and export/delete them so they aren't in the list.

search by developer

  1. Lastly regenerate your certs in XCode and rebooot

    • Reopen xcode
    • regenerate a new cert by going to project -> General --> Signing
    • reselect your "Team Account"

signing setup

  • a new cert should be generated
  • Reboot for good measure - and enjoy being free from this bug ( which Apple should really sort out, if it was at all possible to replicate easily)
UKDataGeek
  • 6,338
  • 9
  • 46
  • 63
1

I recently had the same issue. Keychain Access was the culprit.

Steps: Go -> Utilities -> Keychain Access Keychain Access: Edit -> Change Password for Keychain "login"

Change the password. Close and reopen Xcode, Clean & build again.

If option - Change Password for Keychain "login" - is greyed out:

  1. Make sure under Keychains selected -> login and the padlock icon is open. To open the padlock you need the keychain password. If you do not know the password, go to Step 2.

  2. With padlock unlocked and still option is greyed out. As last resort: Keychain Access -> Preferences Preferences: "Reset My Default Keychains" Reset the login. However be careful as stored keychains will be removed and you may have re-login on other connected devices as well.

1

Most answers will tell you that you have a duplicate certificate. This is true for my case but the answers left out how to do it.

For me, my account expired and I have to get a new certificate and install it. Next, I looked at Keychain and removes the expired certificate but still got the error. What works for me is actually searching for "iPhone" in Keychain and removing all expired certificates. Apparently, some of it are not shown in System/Certificates or login/Certificates.

Hope this helps!

oky_sabeni
  • 7,672
  • 15
  • 65
  • 89
0

I went to Key Access, selected the private key, and added XCode to the list of apps that can access it. That worked for me

Ben Burnett
  • 383
  • 2
  • 4
  • 11
0

If anyone uses Xcode ver. 3.x.x and upgrades from Mac OS 10.7 to 10.8, dev. tools will work just fine except the new codesign binary .. To fix that just copy the old codesign and codesign_allocate binaries (I hope you have backup) to /usr/bin/ folder and rename or backup the new one.

Serbian
  • 9
  • 1
0

I had special characters in the project name,renaming it to remove the characters, question marks, and insuring a developer certificate was enabled fixed the issue.

Arun Bertil
  • 4,598
  • 4
  • 33
  • 59
0

When I experienced this error, it was due to having been in Keychain Access, and choosing 'Disallow' when asked whether I wanted to let the program access a saved password. Going back in and selecting 'Allow' and typing my system password fixed the problem in XCode.

  • Could you please elaborate more your answer adding a little more description about the solution you provide? – abarisone May 22 '15 at 14:43
0

For me the problem was HTTP proxy

Mugen
  • 8,301
  • 10
  • 62
  • 140
0

Here is how I solved the same problem. It may help someone.

I deleted the Development Provisionning Profile (that I was using) from the server, then created one with a slightly different name. I used it and it worked.

Michel
  • 10,303
  • 17
  • 82
  • 179
0

This issue happened for me when I had multiple targets in one project, and I changed the CFBundleExecutable plist property to something other than the target's name.

So, for example, I had the following targets in one project:

  • SomeApp
  • SomeApp WatchKit Extension
  • SomeApp WatchKit App
  • SomeApp Today Widget
  • SomeApp for OS X (this is the target where the codesign error happens)

SomeApp for OS X had its CFBundleExecutable property set to just SomeApp, which not only conflicted with the first target called SomeApp but was different from the target it was meant for. Changing SomeApp for OS X to SomeApp and then renaming the first target worked fine for me.

Kane Cheshire
  • 1,654
  • 17
  • 20
0

For me I had code coverage enabled on the scheme of a framework rather than it's corresponding test scheme. Disabling the code coverage sorted the problem.

Mills
  • 61
  • 3
0

A very simple answer to this very-complicated question. It involves no knowledge of code-signing and everything connected with it.

Take an old app that is not needed any more. Make sure it works, then replace its code with that of the new app having the code-signing error. The old app should now work fine, accomplishing what you wanted with the new app.

Only down side: the working app has the title of the old one.

mbs31
  • 19
  • 3
0

Try finding out the details of this error in the "Build Results" view where the error is shown. On the right side of the line with the error message there is an icon with several lines. This will show you some helpful details.

This way I found out for me it was a duplicate iPhone developer certificate in my keychain - one of which had been expired. Maybe search for "iphone" in your keychain (select "All Items" category first).

Rocco
  • 91
  • 7
0

This issue occured when I added a folder named "Resources" as "Create folder references", and when I renamed "Resources" to another random name, this issue disappeared.

Hope it will help.

GrumpyMelon
  • 303
  • 1
  • 4
  • 10
0

Spent hours figuring out the issue, it's due very generic error by xcode. One of my frameworks was failing with codesign on one of the laptop with below error :

XYZ.framework : unknown error -1=ffffffffffffffff

Command /usr/bin/codesign failed with exit code 1

However, there is no Codesign set for this framework and still it fails with codesign error.

Below is the answer:

I have generated new development certificate (with new private key) and installed on my new mac.

this error is not relevant to XYZ.frameowrk. Basically codesign failed while archiving coz we newly created certificate asks "codesign wants to sign using key "my account Name" in your keychain" and the buttons Always Allow, Deny and Allow.

Issue was I never accepted it. Once I clicked on Allow. It started working.

Hope this helps.

Kiran S
  • 448
  • 5
  • 14
0

In Xcode: Go to Preferences Logout of the current user.

Close Xcode

In Keychain: Go to Login and All items

            - Sort by kind
                 - remove "Apple Worldwide Developer Relation Certification Authority"
                 - remove "Developer ID Certification Authority"
                 - remove "iPhone Developer ...."

Open Xcode

Go to Preferences and Login to you user apple account

- This will reload your developer certificates you previous deleted 

Rebuild the project (Should be a successful build)

Run the build on your native device

Val
  • 1,260
  • 5
  • 23
  • 39
0

I ran into this error code with an existing project that suddenly wouldn't sign after I added three PNG files to the project. It turns out that one of the PNG files was the culprit. All three PNG files were created with Pixelmator, should have the same structure. But it simply wouldn't sign with one of the images. Remove the image, it worked. Add it again, failed. Rename the image, still failed. I wound up building a new image from scratch, all fixed.

Jim Rea
  • 161
  • 7
0

That worked for me was to review all the certificates on KeyChain to be as Use systems Default, all the certificates must to be with this configuration. Was the only thing that worked, and also be shure that no certificates are repeated.

0

For me, I just had to delete "Derived Data" in xcode

Open Xcode (12.3) -> Xcode -> Preferences -> Locations -> Click DerivedData location arrow -> Delete "DerivedData" folder -> Clean and build

0

One solution more works with me, If you installed two versions of XCode and you install the second without uninstalling the first in the same directory (/Developer/), you did it wrong. So the solution that works for me was:

1 - Uninstall the current Xcode version with the command sudo /Developer/Library/uninstall-devtools --mode=all.

2 - Install the first Xcode version you had first.

3 - Again sudo /Developer/Library/uninstall-devtools --mode=all.

4 - Then, all is clean and you are able to install the version you want.

More things: maybe you need to restart the computer after install the Xcode or even (in some cases) install two times the Xcode.

I hope I works it take me a lot of time to know that, good luck!!!

Gustavo
  • 785
  • 1
  • 12
  • 31
0

The solution that worked for me is related to (what I think is) a change of path behavior after upgrading to Xcode 4.2:

You can no longer manually enter "armv6 armv7" but must enter $(VALID_ARCHS) instead: both for the Architectures and Valid Architectures fields under the Architectures section in your project's Build Settings pane. Xcode will automatically replace the statement with 'armv6 armv7'.

This string looks exactly the same as if you would have typed it in manually but nevertheless point to the actual correct paths that will be generated along with your build, ...or at least this is my take on it :P

Unrelated, we used to have "armv6 armv7" as well under Other Signing Flags and now took that out and it works fine. This must be just an extra.

Thanks and happy hacking. Gon

Gon Zifroni
  • 213
  • 5
  • 12
-1

Following steps worked for me

  • Cleaned my device from all provision profiles
  • Cleaned OSx Keychain from my Dev iOS Certificates & Keys
  • From Apple Developer Program regenerated Certificate / Provisioning profile
  • Installed Provisioning profile into my Xcode project
  • Fixed Team issues in Project Target
  • Configured appropriate Code Signing Identity in Project/Target/Build Settings
Delorean
  • 356
  • 3
  • 11
-1

All I had to do is to disable automatic signing, then re-nable it, and choose my team identity. And it worked!

Ahmed Khalaf
  • 1,401
  • 2
  • 15
  • 29
-1

Tried out most of the solutions here and what helped me was cleaning the build folder in XCode using: Product - > Clean and rebuild the project

Yona
  • 1
-1

Steps to Fix this issue:

  1. Go to Key Chain Access.
    1. Select the i-Phone Developer certificate.
    2. Lock the Certificate.( Menu bar - Lock Button)
    3. Give the Machine Password.
    4. Unlock the Certificate.

Now clean and rebuild the project, this issue will resolve.

Kiran Sk
  • 873
  • 10
  • 24
-1

I have solved this issue by following steps.

  1. open keychain access, type "deve"
  2. delete the selected item as in the attached image enter image description here
  3. open xcode and it will ask password type system password.

Hope, it will help.

Wajahat Hussain
  • 234
  • 2
  • 7
-2

The real FIX for me was:
The only problem is I had my Provisioning Profile "invalid" in member center, because that old provisioning profile was generated by old certificate.
Once you regenerate your certificate, or regenerate your Provisioning Profile, make sure you download them and feed them to Xcode.

Almas Adilbek
  • 4,371
  • 10
  • 58
  • 97
-3

I just created a new project, copied all my classes and resources and then it worked!

Alan Moore
  • 6,525
  • 6
  • 55
  • 68
Daniel
  • 1,179
  • 4
  • 18
  • 31