Xcode 11.2.1 - Command CodeSign failed with a nonzero exit code - xcode

I'm working on a SFML app for macOS with the latest Xcode version.
I got a "Command CodeSign failed with a nonzero exit code" error when it tries to sign the SFML frameworks. I added these under "Link Binary with Libraries" and "Copy Files" in Target, under Build Phases. Before, I was working with my local frameworks under /Library/Frameworks, and it was working very well.
Now I need to create an archive .app.
I've tried a lot of things seen on other posts here (like lock and unlock my keychains), but nothing worked. Still got that error.
My SFML Frameworks in "Link Binary with Libraries"
/Users/lounesksouri/Library/Developer/Xcode/DerivedData/Squadro-gqwjbvsooypqaifxxyzhdrahkdpo/Build/Intermediates.noindex/ArchiveIntermediates/Squadro/InstallationBuildProductsLocation/Applications/Squadro.app/Contents/Frameworks/sfml-system.framework/Versions/A: bundle format unrecognized, invalid, or unsuitable
Command CodeSign failed with a nonzero exit code

Ok, I solved my problem, after long hours.
It's a lot more simple to use the script already present in Build Phases tab, generated if you use the SFML App Xcode template (see here the original script). I had tried it at first, but it didn't work so I let it down.
But, in this script, the first three lines are not the good ones, for a normal SFML installation on macOS. We need to modify these lines with the good paths to the Frameworks and lib folders, as follows :
SFML_DEPENDENCIES_INSTALL_PREFIX="/Library/Frameworks"
CMAKE_INSTALL_FRAMEWORK_PREFIX="/Library/Frameworks"
CMAKE_INSTALL_LIB_PREFIX="/usr/local/lib"
FRAMEWORKS_FULL_PATH="$BUILT_PRODUCTS_DIR/$FRAMEWORKS_FOLDER_PATH/"
Secondly, there is still the code signing problem : the archive will created but we will get an error if we start the .app. The solution to this problem is to check Disable Library Validation under Target/Signing & Capabilities to allow the application to load plug-ins or frameworks signed by other developers.
Finally, if we create the archive and launch the application, everything goes normally, as planned.

I faced this problem with the new update of Xcode. I was reading your discussion, and did some accidental modifications. I am definetely not an expert but what I did fixed the problem so I did not receive tgis error anymore. So I added the sfml libraries (5 libraries), whose paths are written in build settings -> framework swarch paths. And this adding automatically added them in Embedded Frameworks under the Build phases section. What I did is unchecking the checkboxes of all 5 libraries "Code sign On copy". Thank you guys for giving me the path for "solving" the problem :))))

For the Code-signing issue:
Open a Terminal,
Go to the Framework folder (cd /Library/Frameworks) and sing them.
choose your identity
security find-identity -vp codesigning
sign them Frameworks!
codesign -s AD90FAFAFAFAFAFAFAF-YOURHASH-9D6 ogg.framework
codesign ... all the others
run and enjoy!

Related

Xcode 11, Command CodeSign failed with a nonzero exit code

Ever since updating (against my will) to Xcode 11, I'm getting this error when I try to build my project:
CodeSign /Volumes/HDD/OpenFrameworks/of_v0.9.8_osx_release/apps/plus-pool-light/pplight-ofx-098/bin/pplight-ofx-098Debug.app (in target 'pplight-ofx-098' from project 'pplight-ofx-098')
cd /Volumes/HDD/OpenFrameworks/of_v0.9.8_osx_release/apps/plus-pool-light/pplight-ofx-098
export CODESIGN_ALLOCATE=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/codesign_allocate
Signing Identity: "-"
/usr/bin/codesign --force --sign - --entitlements /Volumes/HDD/OpenFrameworks/of_v0.9.8_osx_release/apps/plus-pool-light/pplight-ofx-098/build/pplight-ofx-098.build/Debug/pplight-ofx-098.build/pplight-ofx-098Debug.app.xcent --timestamp=none /Volumes/HDD/OpenFrameworks/of_v0.9.8_osx_release/apps/plus-pool-light/pplight-ofx-098/bin/pplight-ofx-098Debug.app
/Volumes/HDD/OpenFrameworks/of_v0.9.8_osx_release/apps/plus-pool-light/pplight-ofx-098/bin/pplight-ofx-098Debug.app: code object is not signed at all
In subcomponent: /Volumes/HDD/OpenFrameworks/of_v0.9.8_osx_release/apps/plus-pool-light/pplight-ofx-098/bin/pplight-ofx-098Debug.app/Contents/Frameworks/GLUT.framework
Command CodeSign failed with a nonzero exit code
I've tried cleaning my project, resetting my login keychain, and restarting my computer, but I still get this error... what to do?
I am building an OSX App using OpenFrameworks, not an iOS App. When I build it in Xcode 10.3 works fine with no errors.
The parts of this question that are unique is that this is for Xcode 11, not 10, and none of the answers for that other question worked for me!
I've resolved the same exact problem by:
Add --deep to the "Other Code Signing Flags" in the "Build Settings".
In the "Signing & Capabilities" of your target click on "+ Capability" in the top left corner and choose "Hardened Runtime".
Then turn on "Disable Library Validation" in the list.
I don't really know if there's any drawbacks by using this capability, however my application compiles and works fine both on macOS and iOS.
You can get this error if you have added a folder to your project as a 'folder reference' (the project will have a blue folder logo in Xcode)
Remove the folder (Trash)
Add folder and select 'Create Groups' instead of 'Folder Reference' at the dialog
Add Folder Dialog
I got the same error after I upgraded to XCode-11 this morning. Builds in the simulator but not on device.
This thread helped fix the issue which I summarized below.
https://stackoverflow.com/a/52628909/9286768
Open keychain access.
Lock the 'login' keychain. (right clicking on "login" in the upper left
panel)
Unlock it, enter your PC account password.
Clean Project in the product menu.
Build it Again.
I fixed this by adding --deep to Other Code Signing Flags in the Build Settings > Signing
I had the same issue for all my Carthage Frameworks, the solution is:
Under Target-> [AppName] -> General -> "Frameworks, Libraries and
Embedded Content"
Select "Do Not Embed" for the option next to the problematic
framework.
More info are in this thread
NOTE: this might not fully solved the issue, never forget to try clean the project, restart Xcode even restart Mac sometimes.
I solved the problem as follows:
After adding 2 ".png" files, Xcode (Version 13.2.1 (13C100)) would not compile anymore. I integrated these 2 files in a .rtf file (generated from Xcode) and I succeeded in compiling again. That's how it goes.
I fixed the problem by making sure the Code Signing Identity in Build Settings was correct - not just general Apple Development and then cleaned the Build Folder in in the Product Menu. When I ran it again it built without error.
I resolved a similar error in Xcode 13 by only changing my Base SDK to the latest SDK (i.e. iOS 15).

How do you fix "code object is not signed at all In subcomponent:" in Xcode 6, Mac OS X Yosemite or Mavericks?

When compiling my application I'm getting the following error:
CodeSign /Users/pupeno/Library/Developer/Xcode/DerivedData/ProjectX-cynmgyozflnwbpamwnpsnhgshuyq/Build/Products/Debug/Project\ X.app
cd /Users/pupeno/Projects/ProjectX
export CODESIGN_ALLOCATE=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/codesign_allocate
Signing Identity: "Mac Developer: José Fernández (G4PM7K38JH)"
/usr/bin/codesign --force --sign A21FB31766DDCBB28FBB4E4DD86E3743024A45F3 --entitlements /Users/pupeno/Library/Developer/Xcode/DerivedData/ProjectX-cynmgyozflnwbpamwnpsnhgshuyq/Build/Intermediates/ProjectX.build/Debug/App.build/Project\ X.app.xcent --requirements =designated\ =>\ anchor\ apple\ generic\ \ and\ identifier\ \"$self.identifier\"\ and\ ((cert\ leaf[field.1.2.840.113635.100.6.1.9]\ exists)\ or\ (\ certificate\ 1[field.1.2.840.113635.100.6.2.6]\ exists\ and\ certificate\ leaf[field.1.2.840.113635.100.6.1.13]\ exists\ \ and\ certificate\ leaf[subject.OU]\ =\ \"XHT4M2DATL\"\ )) /Users/pupeno/Library/Developer/Xcode/DerivedData/ProjectX-cynmgyozflnwbpamwnpsnhgshuyq/Build/Products/Debug/Project\ X.app
/Users/pupeno/Library/Developer/Xcode/DerivedData/ProjectX-cynmgyozflnwbpamwnpsnhgshuyq/Build/Products/Debug/Project X.app: code object is not signed at all
In subcomponent: /Users/pupeno/Library/Developer/Xcode/DerivedData/ProjectX-cynmgyozflnwbpamwnpsnhgshuyq/Build/Products/Debug/Project X.app/Contents/Frameworks/Paddle.framework
Command /usr/bin/codesign failed with exit code 1
I'm using two frameworks, Paddle and Sparkle and they are configured to sign on copy:
Looking for a solution to this problem I found many recommendations to do a --deep sign, which is officially discouraged by Apple (Using the codesign Tool's --deep Option Correctly).
I also found the article Code Signing and Mavericks which also explains that using --deep is wrong and offers an alternative: using a script to generate signatures for each framework. I think this is something that was needed before Xcode had the option to sign on copy, but I gave it a try anyway. It made no difference, I still get the same error. Looking at the logs, the bundles are getting signed with the "Sign on copy" option, so, adding that script caused them to get signed twice.
My code signing identity is configured as follows for the whole project and each target just inherits it:
I understand that's not the appropriate signature for Release, but for now, we are just trying to get this to build and run locally.
Any ideas what's wrong? Any ideas how to fix it?
I understand that
For me I had to go to the Project build settings and set Other Code Signing Flags to --deep. The problem was that my framework in the project was not signed.
For All who still are facing this issue, Please make sure 'Product Name' in build setting matches with 'Executable file' set in info.plist.
Generally when we duplicate exiting code, we simply change either product name or Executable file, and this mismatched creates a issue.
The problem was that the Framework, Paddle.framework, became corrupt. The symlinks were resolved to the files they were pointed to, so, compilation worked just fine, but signing didn't.
Re-downloading the framework and copying it into the project fixed the problem.
For me the solution was to re-Add a resource folder (checking Create groups instead of create folder references).
Adding ANOTHER thing to check if you get this error:
In the Build Phases pane for your Project's application target, make sure the Embed Frameworks phase comes before the Link Binary With Libraries phase:
I'm running macOS 11.2.3 and Xcode 12.4.
An Aside:
It's utterly ridiculous how fragile and broken code-signing remains. It's 2021 and this post alone has 87 different "fixes" to solve the same damn error message. There's just no excuse for wasting developers' time like this. Fix your IDE, Apple.
For me this problem was resolved by a simple "clean build folder" action, keyboard shortcut: shift+option+command+K.
I'll admit codesigning is still a black art to me, but in Xcode 6 I found that removing all of my signing scripts (which were necessary in Xcode 5, along with --deep flags) and additional signing flags, and just using the "codesign on copy" option in the Framework's Copy Files phase of the build worked flawlessly for me.
For me, it turned out that I had inadvertently added a bash build script to the target. Making sure I had no sneaky scripts accidentally copied into the target fixed the issue.
Product -> Cleanup build folder
Build/Compile project
for me, one of the frameworks I was including, had another of the frameworks marked as "embed and sign"... which you can't do... only the app should be doing that.
marking the grandchild framework as "do not embed" in the child framework, removed this issue.
I faced this problem after adding fastlane to upload screenshots to App Store Connect automatically. I had to remove fastlane from the project and clean the build folder to make it work again.
Using CocoaPods in the project it helped me to go to the Pods project, select a problem framework and set the correct developemtn team on Signing & Capabilities page or Build settings with All levels set.
In my case I both had a subproject and a subproject of that subproject (i.e. a sub-subproject) to which I had added the same Swift package dependency. Keeping it in the sub-subproject and removing it from the subproject solved the issue.
As shown by the number of answers here the causes for the error can be many.
In my experience building a complex project with multiple level of Frameworks, Static libraries from Swift packages and Pods you should follow these rules:
A Framework can't embed and sign another framework: only and App can do that.
A Framework can use a static library (from a Swift Package for instance) but the library must be present only in the Framework and not in the main App. If the same library is embedded in both Framework and main App, in some unknown circumstances, this error occurs.
Be sure to clean the build folder after each change to frameworks and library structure/embed

Jenkins vs. Xcode plugin - codesign troubles

I have updated to OS X Yosemite and also Xcode 6.1 (downloaded from the developer site), from this time I have had the problem with the building as in the log file I see the note "Warning: --resource-rules has been deprecated in Mac OS X >= 10.10!". Does someone know how to use Xcode plugin without "resource-rules" flag? Thank you.
Everything is ok with Jenkins plugin. Just product settings is incorrect.
Open the "Build Settings" tab of your project. Searched "Code Signing Resource Rules Path", it was empty for me. Change to: $(SDKROOT)/ResourceRules.plist
credits goes to Adams Blair who described this problem with SDK2.2
https://stackoverflow.com/a/7919137/2124345
Update
This solution doesn't remove the warning itself. But i'm pretty sure that warning isn't a problem. The problem is that without this setting ResourceRules.plist files isn't generated in Payload folder, and build process stops because file is missing.
And again, it's not related with jenkins plugin at all. Same error happens with xcrun -sdk iphoneos PackageApplication. Jenkins just calling this command line as a build step.
The answer provided by Julius Lisauskas will resolve the warning, but it is actually just a workaround for a bug that exists in the Jenkins Xcode plugin xcrun.
As mentioned in Apple Technical Note TN2206:
Systems before OS X Mavericks documented a signing feature
(--resource-rules) to control which files in a bundle should be sealed
by a code signature. This feature has been obsoleted for Mavericks.
Code signatures made in Mavericks and later always seal all files in a
bundle; there is no need to specify this explicitly any more. This
also means that the Code Signing Resource Rules Path build setting in
Xcode should no longer be used and should be left blank.
It is thus no longer possible to exclude parts of a bundle from the
signature. Bundles should be treated as read-only once they have been
signed.
There is an issue raised on the Jenkins Xcode plugin regarding this bug that concludes the bug lies in Xcrun.
As specified in another answer, you can also just not specify the distribution certificate to sign with and it will package correctly.

xcode 6 beta 7:A signed resource has been added modified or deleted.

When I'm running the application on device aftercleaning, removing derived data, first time it runs without any issues.
Second time when I'm trying to run, it say's "A signed resource has been added modified or deleted."
On the simulator app run's without problem.
I think it's because of extensions, I have editing, share and today extensions, when I'm deleting this extensions, then I can run second time without this message.
The problem has been since from xcode 6 beta 5.
Maybe issue related to provisioning profiles and signing ? I has created different provisioning profiles for each extension target.
So my question is, how can I fix this ? How can I run on the device second time without cleaning project?
It is still not fixed in XCode 6 RTM. But I found an easy walk around. Simply delete the ShareExtension.appex folder under your build. Then rebuild again. You don't need to clean project, so rebuild is quite fast.
A actually alias the command to do the cleaning
rm -rf ~/Library/Developer/Xcode/DerivedData/<your_app>-*/Build/Products/Debug-iphoneos/ShareExtension.appex/
I used a slight modification of Cloud Xu's script to delete both the .appex and .appex.dSYM
rm -rf ~/Library/Developer/Xcode/DerivedData/YourAppName-*/Build/Products/Debug-iphoneos/com.yourcompany.Name.extension.*
You can put this in your scheme so that it executes with every build:
Edit scheme... > Expand the Run mode in the sidebar > Pre-actions > Click '+' > New Run Script Action.
Edit:
There is an another workaround: for each extension target containing .swift file, add build pre-action in project running scheme configuration:
touch "${PROJECT_DIR}/SOME SWIFT FILE IN EXTENSION.SWIFT"
So I've found a workaround for this issue. For now we can't have swift code in extensions. As mentioned in the comment
When removed all extension targets that contains swift code it's started working normally. I think it's a bug in xcode, for now if we have extension with swift code, don't know why, but second time run gives "A signed resource has been added modified or deleted." error.

Can you create Mac .app distribution from the command-line instead of from within Xcode?

Is it possible to go from an .xcarchive bundle to an .app bundle without using the Xcode Organizer? I'd like to create an automated build and get the final .app file that I can distribute. Using xcodebuild with the archive target works great for getting the .xcarchive file, but not for the final app.
With the iOS SDK, there's a PackageApplication tool you can use with xcrun, but this doesn't appear to exist with the OS X SDK.
I'd also like to do this so I can hopefully get more diagnostics from the Distribution process, which is failing for me right now with the infamous 100021 OS error code.
Have you looked inside the .xcarchive bundle? It's just a folder. Your .app targets should be inside, in a Products subfolder.
In Finder, right-click the archive and click Show Package Contents. in Terminal, use cd.
Try the -exportArchive flag in the xcodebuild command:
xcodebuild -exportArchive -exportFormat app -archivePath <path to .xcarchive> -exportPath "My App.app" -exportSigningIdentity "Developer ID Application: My Software Company"
This command is present in Xcode 5.0.1. See the man page for more details on the optional arguments. This example exports a Developer ID signed application.
Here is what I have discovered about this issue:
As previously suggested, the xcodebuild's archive buildaction is good for getting the .xcarchive, but there does not appear to be an actual way to perform the validate or distribution commands from the command-line. I hope this eventually turns out to be false.
I was able to trick the validation tool by removing the embedded symbolic links in the embedded framework directories. This works, but after discussing with Apple support it turns out this is tricking the tool and not actually producing a valid result.
Apple support says they see this error code if one of the .plist files in an embedded framework is invalid. It turns out, in my example, I had 3 embedded frameworks and 1 of them had an empty .plist file, likely from me hand-building the project. After fixing that, the build would continue happily.

Resources