297
votes

Already tried : Code Sign Error on macOS Sierra, Xcode 8

Please see image showing error enter image description here

CodeSign /Users/gururajtallur/Library/Developer/Xcode/DerivedData/Flow-bkqjkvtmvjovpyepfjeyqmjpintj/Build/Products/Debug-iphoneos/Super\ Flow\ Flip.app
    cd "/Volumes/Development/Project/Top Best Games/19. Lets Flow/35/let's FLOW - source/proj.ios_mac"
    export CODESIGN_ALLOCATE=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/codesign_allocate
    export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"

Signing Identity:     "iPhone Distribution: New Free Games (2CHN583K4J)"
Provisioning Profile: "Super Flow Flipp AppStore"
                      (c6c30d2a-1025-4a23-8d12-1863ff684a05)

    /usr/bin/codesign --force --sign E48B98966150110E55EAA9B149F731901A41B37F --entitlements /Users/gururajtallur/Library/Developer/Xcode/DerivedData/Flow-bkqjkvtmvjovpyepfjeyqmjpintj/Build/Intermediates/Flow.build/Debug-iphoneos/Super\ Flow\ Flip.build/Super\ Flow\ Flip.app.xcent --timestamp=none /Users/gururajtallur/Library/Developer/Xcode/DerivedData/Flow-bkqjkvtmvjovpyepfjeyqmjpintj/Build/Products/Debug-iphoneos/Super\ Flow\ Flip.app

/Users/gururajtallur/Library/Developer/Xcode/DerivedData/Flow-bkqjkvtmvjovpyepfjeyqmjpintj/Build/Products/Debug-iphoneos/Super Flow Flip.app: resource fork, Finder information, or similar detritus not allowed
Command /usr/bin/codesign failed with exit code 1

In Code Sign section its allowing me to select profile and certificate...but still giving error. enter image description here

enter image description here

How to fix this problem ?

24
did you make clean and "alt" clean ?thorb65
means? I just recreated certificates from xcode accounts and re generated profiles in website and re tried...still no luck.iPhoneProcessor
Arnold Roas answer below did the trick for my project. But you also might have to do a Product > Clean in XCode for the compile to succeed afterwards.Fredrik Johansson
plus for cocos2d-xfnc12

24 Answers

656
votes

Solution 1:

Apple Developer Website Answers above problem Here.

Execute below command in terminal : First goto projects root folder

 xattr -cr <path_to_project_dir>

Clean Xcode and Re Build. Cheers

Solution 2:

Just go to project root directory and run this command xattr -cr .

xattr -cr .

Clean Xcode and Re Build. Done.

Solution 3:

You can fix this problem by finding files which holds finder information.

In terminal, goto project root directory and execute

ls -alR@ . > kundapura.txt

This creates kundapura.txt in current directory. Now search for com.apple.FinderInfo and clear this attributes for all files. You can do it like this

xattr -c <filename>

Example: xattr -c guru.png

Once you clear all then code sign works. Clean Xcode and Re Build. Cheers

Solution 4: Inspired by Mark McCorkle's Answer

In terminal, goto project's root directory and execute one by one command

  find . -type f -name '*.jpeg' -exec xattr -c {} \;
  find . -type f -name '*.jpg' -exec xattr -c {} \;
  find . -type f -name '*.png' -exec xattr -c {} \;
  find . -type f -name '*.json' -exec xattr -c {} \;

Clean Xcode and Re Build. Done.

179
votes

The error is from attributes inside your image files. This happened from our graphics designer saving images from photoshop with attributes.

Here is a simple command to find all of your png files and remove their attributes. Run this in your projects root directory from terminal. Clean and rebuild; problem solved.

find . -type f -name '*.png' -exec xattr -c {} \;
104
votes

If you have this error when codesigning an app:

resource fork, Finder information, or similar detritus not allowed Command /usr/bin/codesign failed with exit code 1

Go to your project root folder and execute

find . | xargs -0 xattr -c

This will clear attributes for all files.

In Sierra, the rules on what can be in a signed bundle have been tightened, and resource forks are no longer allowed. AppleScript has been saving information in resource forks forever, although that information has been unused for a long time. With Sierra, when you save a script, this resource fork information will no longer be saved.

It means you cannot codesign a script that was last saved in a version before Sierra; you have to save in Sierra to be able to sign in Sierra.

The people likely to be affected by are who bundle other scripts within their scripts (cordova?). They will not be able to sign the container script until all the embedded scripts have been resaved under Sierra.

UPDATE:

Seems like this also works:

xattr -rc .

If you have any insufficient permissions error try to prepend sudo: sudo xattr -rc .

36
votes

The easiest way to handle attributes on your source files is to have Xcode clear up the archive before it runs codesign. To do this:

  1. Select your target in XCode
  2. Select the Build Phases tab
  3. Press the + symbol
  4. Select New Run Script Phase
  5. Enter the following for the script:

    xattr -cr ~/Library/Developer/Xcode/DerivedData || echo Clear

Now when you build your target it will clear out any attributes that would have broken codesign. By clearing out at this stage you don't have to alter your source code / project directory.

The "|| echo Clear" part of the script ensures that the project build continues even if xattr errors.

This method is good if you use programs such as DropBox on your code repository that add the attributes, as it doesn't change your source project, only the built archive.

You may need to change the path to match your DerivedData directory - this path will be shown next to the codesign error.

xattr codesign xcode fix

30
votes

I have used following command. Use terminal window. Navigate to your Project and execute following:

xattr -rc .
24
votes

There is official Apple answer for this issue in Technical Q&A QA1940.

This is a security hardening change that was introduced with iOS 10, macOS Sierra, watchOS 3, and tvOS 10.

Code signing no longer allows any file in an app bundle to have an extended attribute containing a resource fork or Finder info.

To see which files are causing this error, run this command in Terminal: xattr -lr <path_to_app_bundle>

You can also remove all extended attributes from your app bundle with the xattr command: xattr -cr <path_to_app_bundle>

<path_to_app_bundle> can be replaced with directory of your Xcode project. For example ~/Development/MyProject

17
votes

All about clearing files is fine, but tedious for multiple projects.

graphics apps, (like photoshop in old versions) write additional info (we now call it metadata..) in an old fashion in external files, or they came frm older OSX, files like:

"com.apple.ResourceFork" and "com.apple.FinderInfo", when unzipping folder, for example.

Xcode 8 refuses to add it to a build (as You added them to a project with a "git --add ." maybe..) You can find in terminal recursively and delete them, but can be tedious.

I wrote a small free utility to delete it.. hope it can help..

https://itunes.apple.com/us/app/cleandetritus/id1161108431?ls=1&mt=12

12
votes

For those (like me) who are just trying to develop an app without having to strip extended attributes on every new photoshop created PNG added to the macOS target, you can temporarily disable code signing by adding a user defined build setting:

CODE_SIGNING_ALLOWED = No 

Obviously, one distributing an app needs to eventually deal with the issue but this enables development in cases like mine where it wasn't necessarily straightforward to omit code signing in Sierra (on past OS X / Xcode it was easier to do so).

Per RGriffith's comment, here are a few screenshots for those who aren't sure how the custom build setting is added.

enter image description here

enter image description here

11
votes

Simple solution:-

How I did [Working for me]

Step 1:- Go to this folder - from your finder press option Go - > Go to Folder

then type your project path like this example:- Library/Developer/Xcode/DerivedData/yourprojectname/Build/Products/Debug-iphoneos

Now you can see a window pop with list of available File, There you see yourApp.app file [ Don't do anything just wait for step 2].

Step 2:- Open new Terminal and type just cd then just drag step 1 yourApp.app to terminal, now you will get the path for the app, now press enter button.

Step 3:- Now type this command **

xattr -rc .

Don't miss "."(Dot) press enter button.

That's it, Go to your Xcode project and clean and run again.

10
votes

-----In case you can't apply the solutions above, because of lack of bash knowledge or something else.

I had this problem as soon as I enabled iCloud Drive on my Sierra. And my project was in a folder which was synced with iCloud Drive. I suppose this is what adds those additional attributes.

Temporary solution:

Disable iCloud Drive for the folder where your project is.

4
votes

You will need to delete the app bundle folder and rebuild the app as explained below.

My app is called: augment

In terminal window, goto your app folder e.g.: cd /Users/username/Library/Developer/Xcode/DerivedData/

In terminal window run command for your app folder e.g.: xattr -cr augment-flmbiciuyuwaomgdvhulunibwrms

Clean>Build>Run.

There is also a free app on Mac Appstore called "CleanDetritus" which will do removal of these.

2
votes

This problem came to me yesterday.

(What's wrong) I updated image resources by manually replacing file in finder and I failed with this compilation error.

(What's right) Don't update image in this way. After that I dragged images to 'xcassets' in Xcode. No more error appear again.

2
votes

The problem is in the derived data, You should clean the derived data and then clean the project and build. Please check this link.

1
votes

My problem is every change I make in the code and execute again the error reappears. Then I find a solution to execute the command automatically every compilation/execution of code.

Thanks to @rich-able I discovered "Run Script". Then I put the command "xattr -cr ." in the field.

XCODE Solution

1
votes

The simplest fix may be if you are using git. Try:

$ git stash
$ git stash pop

Git does not store file metadata, the above will strip it all away.

1
votes

Open terminal and just run this command.

xattr -cr "path to .app file"

0
votes

My problem was that I used cordova to build the app around 1 year ago, but it wasn't compatible with the new version of xcode, so I simply used cordova build ios and it worked again.

0
votes

One of the best solution is Go to terminal type this

xattr -cr "Full path of your project"

To find full path of your right click on Xcode project->get info -> copy path and replace with . Then type below command

xattr -cr "Full path of your project"

Clean and build done.

0
votes

If the xattr commands doesn't the trick this may be due to an XCode 9 bug: let's try to remove and re-add the resource folder (it was a .xcassets in my case) containing the affected files from Xcode. (you should understand which are the affected files previous through the xattr -lr command)

0
votes

I'm also facing the same issue, got fixed by just restarting my Macbook.

0
votes

I found that if I add color tag on the folder under DerivedData, it will give the above error when debug on device.

Remove the color Tag fix this error for me.

enter image description here

0
votes

You can remove the derived data Xcode -> Preferences

And click on the arrow below Derived Data, and empty the folder Derived Data

0
votes

I don't know what happened to me, but when I was running flutter app on simulator, I was encountered by the error. I used flutter clean command and removed the derived data and then everything goes fine.

0
votes

My .app was on a network mounted drive.

codesign -f -vv --preserve-metadata=entitlements -s {*my Apple distribution cert SHA*} my.app
my.app: resource fork, Finder information, or similar detritus not allowed

I don't know if too long path or the fact it was on a NAS device was a problem. I copied the .app to my local Downloads directory, and then was able to codesign.

my.app: signed app bundle with Mach-O thin (arm64) [*com.something.my*]