323

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 ?

Guru
  • 21,652
  • 10
  • 63
  • 102
iPhoneProcessor
  • 4,980
  • 6
  • 27
  • 49

26 Answers26

703

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.

Solution 2:

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

xattr -cr .

Clean Xcode and Re-build.

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.

starball
  • 20,030
  • 7
  • 43
  • 238
Guru
  • 21,652
  • 10
  • 63
  • 102
  • 7
    This fixed code sign error in Xcode 8. Great solution. – iPhoneProcessor Sep 24 '16 at 12:40
  • 4
    I have 110 files with that. What would be a bash command which would automatically treat all of them? – Fawkes Sep 26 '16 at 12:24
  • I simply used find . -type f -name '*.*' -exec xattr -c {} \; for tons of files even including the .xib files. one of my .aif file was killed... please correct me if I was wrong. – Jiulong Zhao Oct 11 '16 at 00:00
  • @JiulongZhao, sorry not getting what's wrong with your execution. Please post your problem in separate question...some experts may help. – Guru Oct 11 '16 at 05:18
  • @TDM, open terminal and goto project root directory and execute. https://app.box.com/s/usdq26vib991jx0tk6fulggg6p3p7ic3 – Guru Oct 18 '16 at 17:19
  • Thanks. I actually ended up figuring it out, but that didn't seem to fix it. Will try Solution 2 – TDM Oct 18 '16 at 17:22
  • @NagarajS Did you try both solution 1 & 2 ? – Guru Nov 16 '16 at 12:23
  • How can that also happen for nib files?! -rw-r--r--@ 1 Apple staff 6905 Jun 26 2015 LibraryVideoViewController.xib com.apple.FinderInfo note that xcode didn't show the error for the nib file – hasan Nov 18 '16 at 12:47
  • 1
    I was building for iPhone 7 Plus simulator without issue, but then I switched to build on a real device for testing and when I switched back to the simulator, I got this error. Solution 1 worked for me, thanks a bundle. – Matthew Corway Jan 13 '17 at 18:12
  • I've been using Xcode for 6 years during my off time. I code professionally at work with Visual Studio and Eclipse for 6 years. Comparatively, I can't say enough how terrible Xcode is to utilize. – ConfusedDeer Mar 10 '17 at 05:40
  • 1
    By the way, the xattr -rc fix won't work with tif images. You have to remove tif images from the project. I guess tif images come under the heading of "detritus" according to Apple. – Jim Merkel May 01 '17 at 23:57
  • 1
    Great answer except the fact I had to do the same thing with "*.json" files - in one of them there was my problem hidden. – Marek Manduch Jul 03 '17 at 15:37
  • Why did you remove credit to my answer? ;-) @Fawkes You can try file specific bash command like Mark McCorkle answered. – Mark McCorkle Jul 25 '17 at 14:46
  • @MarkMcCorkle Solution 1: Inspired by Mark McCorkle's Answer..Updated Now..Cheers – Guru Jul 25 '17 at 14:59
  • 1
    @MarkMcCorkle I just stated the reason of this problem appearing in the first place and as mentioned in my answer if you're out of luck with understanding how bash works, you can do the dumb way and at least be sure you'll not encounter that again or apply a code which is not your own in your terminal. Since my answer was written ages ago, you can be sure I managed to solve it (; – Fawkes Jul 26 '17 at 14:27
  • The statement was for Guru. It was just a quote with your name in it @Fawks. No worries, problem solved. ;-) – Mark McCorkle Jul 28 '17 at 17:31
  • 1
    First solution worked like a charm in XCODE 9...thank you! – Apneist Oct 19 '17 at 12:12
  • 1
    Worked for Xamarin iOS app as well. Very nice +1 – Dan Beaulieu Dec 27 '17 at 02:44
  • 1
    https://stackoverflow.com/questions/48378604/xcode9-code-sign-error-in-ionic3-project please check, thank you! – Yuyang He Jan 23 '18 at 02:46
  • 1
    Solution 1 fixed this issue with Flutter 1.0.0.0 'myapp' sample built and run from VSCode. – Seamus Jan 04 '19 at 15:05
  • 1
    You can also get this problem with your font files, in my case was simply fixed with: `find . -type f -name '*.ttf' -exec xattr -c {} \;` – Mick Byrne May 03 '19 at 05:19
  • 1
    I'm using ARKit, I imported a 3d image .dae file and it's .jog texture from from blender.org and got this error. What fixed it for me was the 2nd option but I had to to cd to the art.scnassets folder to get to the image causing the problem – Lance Samaria Jun 12 '19 at 03:58
  • 2
    Perfect, very good explanation. BTW, the first command is a bit confusing, instead of `xattr -cr ` it should probably read `xattr -cr `, or just `xattr -cr .` Works like a charm! – fbitterlich Jun 21 '19 at 23:46
  • 1
    If you get the error "option -c not recognized" when running the `xattr` command, it's probably because you have the GNU coreutils version in your path ahead of the stock macOS version. You can choose the correct `xattr` by instead running: `/usr/bin/xattr -cr `. – s3cur3 Oct 08 '19 at 20:30
  • 1
    @fbitterlich thanks! working for me. Just go to project root directory and run this command `xattr -cr .` – IOS Singh Dec 05 '19 at 07:33
  • 1
    I used solution 4 and it worked, but right after changing something in the code(commenting an import) giving me again this problem. Now if I uncomment it, it still giving me the same error. so might have to run solution 4 again. Is there any permanent solution to this? – Alohomora Nov 02 '20 at 07:04
  • 1
    Addition: Please don't forget to check your local packages that are using assets. You might not find `com.apple.FinderInfo` within your project but from the local package folders. – RockingDice Jul 17 '21 at 06:13
185

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 {} \;
Mark McCorkle
  • 9,349
  • 2
  • 32
  • 42
  • 12
    This should be the accepted answer. Simpler, faster, and requires no manual effort. I had 80 files with problems, according to @NatureFriend's answer. – Roger Oba Sep 29 '16 at 23:32
  • One quicker terminal-less solution for me was just to drag all images in ImageOptimizer (which trashes all useless attributes also). – blackjack75 Oct 04 '16 at 15:48
  • I had saved a new icon from pixelmator and had the same issue. Thanks. – Guy Lowe Feb 18 '17 at 02:26
  • This worked for me.. I was getting permission denied on the above 'xcattr -cr' command (even directed to do via Apples documentation listed above: https://developer.apple.com/library/archive/qa/qa1940/_index.html Running Xcode 9.3 on High Sierra 10.13.4. – Randoramma Jul 05 '18 at 16:36
  • I searched far and wide, for days. And this was the issue. I could deploy to a smartphone, but not build my application. All I did was change one picture in the resources. I worked with Xamarin.forms and Visual Studio, and the error VS generated seemed to be totally unrelated. Sometimes "native linking failed", then just some random libary not beeing compatible, but in the end., those errors were all bullsh.... it was the image containing meta data... – innom Aug 22 '22 at 09:17
109

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 .

Arnold Roa
  • 7,335
  • 5
  • 50
  • 69
38

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

A.Badger
  • 4,279
  • 1
  • 26
  • 18
  • 1
    The problem only appears for me in a project created from an otherwise-identical project using ⌘-D in the Finder. For some reason, none of the more popular solutions worked for me. This one did. – clozach Aug 24 '17 at 17:49
  • 1
    THANK YOU! after 2 hours of searching for a solution this worked. – Carter Cobb Mar 10 '19 at 18:48
  • 1
    Finally! After hours of trying other solutions, this fixed it!! Try this first, but substitute the path shown by the codesign error – jmf1205 Jun 26 '19 at 07:30
  • for me, the issue was an image in source code... so I added a run script which did this xattr -cr "$PROJECT_DIR" – Paul Stevenson Jan 10 '20 at 23:34
  • many thanks, this still works. In my case I added xattr -cr ~/Users/msc/OneDrive/01 Work/APP/Flutter/lts-flutter/build/ios/Debug-iphoneos || echo Clear – M4trix Dev Jan 12 '20 at 20:20
  • xattr -lc, suggested in another answer, confirmed that the attributes in question were indeed from DropBox since my project folder is inside my DropBox folder. This suggestion to strip those attributes in the DerivedData folder worked perfectly and left my DropBox folder intact! – Thunk May 25 '20 at 17:53
  • This works for me. I'm using flutter, ios build. With the Mac OS Big Sur, Xcode Beta 11 – Darshana Aug 17 '20 at 04:20
34

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

xattr -rc .
Ram G.
  • 3,045
  • 2
  • 25
  • 31
  • 1
    Yes, sometimes only clearing attrs inside Project directory helps.. Lame Apple, why to make such crappy things – Anton Malyshev Feb 21 '18 at 23:43
  • In addition to the top voted answer this also worked as an alternative – Lance Samaria Jun 12 '19 at 04:13
  • I also had to clean the project folder afterwards for this to work – Lance Samaria Jun 12 '19 at 04:57
  • just note that this command will also remove the folder's custom icon AND kill aliases in the folder (they'll stop working). so if you do have any aliases, back them up first, then restore after running the command. you'll also have to restore the custom icon. – Leo Braun Feb 12 '23 at 10:00
24

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

comrade
  • 4,590
  • 5
  • 33
  • 48
  • After working through almost all other proposed solutions the `xattr -lr ` finally lead to the right files. Got a Localizable.strings from the agency with Finder-Tags and those caused the Codesign to fail. – JanR Jan 24 '18 at 16:58
  • I wasted 2 days on this and this solution finally worked for me! – bhakti123 Nov 16 '18 at 08:38
17

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

ingconti
  • 10,876
  • 3
  • 61
  • 48
13

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

Bobjt
  • 4,040
  • 1
  • 29
  • 29
11

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.

Abdul Nasir B A
  • 1,077
  • 2
  • 8
  • 25
10

-----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.

Fawkes
  • 3,831
  • 3
  • 22
  • 37
  • I moved from iCloud Drive to the Desktop and works properly. Thanks – drasick Oct 05 '16 at 16:42
  • This was part of the solution for me. I had a project on my desktop which was being backed up to iCloud under Sierra. I still needed to type xattr -rc . in the terminal to delete the offending files after moving the project off of the desktop. None of the other solutions worked for this step – Roger Pingleton Oct 06 '16 at 20:21
  • This was also the problem for me: iCloudDrive causes this really annoying error, I reported a bug to Apple -> 31740606 – LukeSideWalker Apr 20 '17 at 20:15
  • This was essentially my problem as well, but I didn't have to disable iCloud for my project folder, or move the project folder, or anything like that. I just went into Xcode Prefs->Locations->Advanced and selected the "Unique" option for Build Location. I had been using a build location in subfolder of the xcode project file, which was on the iCloud drive. I think the default is Unique, and I don't know why I ever changed it, maybe to make it easier to find the executable after a build. – daver Jun 16 '20 at 04:29
4

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.

velhala
  • 161
  • 1
  • 5
  • 1
    I'm using Flutter to generate the iOS app and Clean>Build>Run from Xcode solved the "resource fork, Finder information, or similar detritus not allowed" error on flutter console. – Juan Valera Mar 11 '18 at 18:38
  • It worked, thanks! The solution for me was executing "xattr -rc ." in the derived data project folder instead in the project folder. – BIOS-K Feb 29 '20 at 01:56
2

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.

ManuQiao
  • 708
  • 8
  • 20
2

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

Andrey
  • 722
  • 7
  • 11
1

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.

Rajesh Maurya
  • 3,026
  • 4
  • 19
  • 37
1

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.

emp
  • 3,350
  • 1
  • 22
  • 19
  • I had this issue under Xcode 9. Solution above fixed the issue. You should have project under git source control and haven't committed any file yet. – Anessence Oct 16 '17 at 04:15
1

Open terminal and just run this command.

xattr -cr "path to .app file"

Idrees Ashraf
  • 1,363
  • 21
  • 38
1

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

JerryZhou
  • 4,566
  • 3
  • 37
  • 60
0

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.

Frederik Witte
  • 1,167
  • 2
  • 11
  • 35
0

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)

Joe Aspara
  • 1,137
  • 1
  • 13
  • 26
0

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

Yogesh Dalavi
  • 73
  • 4
  • 15
0

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

Irfan
  • 4,301
  • 6
  • 29
  • 46
0

You can remove the derived data Xcode -> Preferences

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

Mickael Belhassen
  • 2,970
  • 1
  • 25
  • 46
0

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.

Ankur Lahiry
  • 2,253
  • 1
  • 15
  • 25
0

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*]
Ben Butzer
  • 915
  • 10
  • 24
0

This happened to me as well when I duplicated a .plist file and edited it, instead of creating a new one. the xattr -lr <path> command helped me identify the problematic file.

aclima
  • 630
  • 1
  • 11
  • 20
0

My issue was related to unintended changes on framework integrated using Carthage. I had modified one line in framework by mistake and it didn't show up in git because dependency build folder was ignored from git.

Solution : Deleted framework folder in Carthage and rebuilt it.

Abhijith
  • 3,094
  • 1
  • 33
  • 36