Found an unexpected Mach-O header code: 0x72613c21 in Xcode 7
Solution 1
Check two things for every framework:
- The Mach-O type of the framework (in Build Settings of the framework target)
- Whether you copy the framework by putting it in Build Phases -> Embed Frameworks (or Copy Bundle Resources as mentioned by a. brooks hollar)
If the Mach-O type of the framework is "static library", it should not be put in embed frameworks; if the Mach-O type is "dynamic library", it should be put in embed frameworks.
In my case it was SocketRocket I added manually which has both a static library target and a dynamic library target with the same framework name. After deleting the static library target and only embed the dynamic library framework, the problem disappears.
Note:
If you don't have access to the source project, you can manually check if it's a dynamic or static framework using this approach: https://stackoverflow.com/a/32591983/308315
Solution 2
I don't know why but somehow pods appeared to become an embedded binary. So I had to remove it, pod install once more, and the issue disappeared.
On Xcode 11 you need to change it to Do Not Embed
in the Frameworks, Libraries, and Embedded Content.
Solution 3
Double check Build Phases -> Copy Bundle Resources for a framework or other binary that shoundn't be there.
In my case, it was a 3rd party library (Parse) that I had added.
Solution 4
In my case, I have a framework manually dragged into my project, and it is listed in General
->Embedded Binaries
, which cause error Found an unexpected Mach-O header code: 0x72613c21
. After i moved it from Embedded Binaries
to Linked Frameworks and Libraries
, problem solved.
Solution 5
If you (potentially but not necessarily) used FirebaseSDK (especially Analytics) and get Mach-O error while running, archiving and uploading, try this:
Add this as a build post-actions script.
rm -rf "${TARGET_BUILD_DIR}/${TARGET_NAME}.app/Frameworks/FirebaseAnalytics.framework"
rm -rf "${TARGET_BUILD_DIR}/${TARGET_NAME}.app/Frameworks/GoogleAppMeasurement.framework"
rm -rf "${TARGET_BUILD_DIR}/${TARGET_NAME}.app/Frameworks/FIRAnalyticsConnector.framework"
if you added widgets and/or other plugin extensions add these lines as well:
rm -rf "${TARGET_BUILD_DIR}/${TARGET_NAME}.app/PlugIns/FirebaseAnalytics.framework"
rm -rf "${TARGET_BUILD_DIR}/${TARGET_NAME}.app/PlugIns/GoogleAppMeasurement.framework"
rm -rf "${TARGET_BUILD_DIR}/${TARGET_NAME}.app/PlugIns/FIRAnalyticsConnector.framework"
Brief explanation: The below quote is from the relevant discussion under https://github.com/firebase/firebase-ios-sdk/issues/6472 explains the reason behind this problem.
... so right now the firebase framework artifacts are being copied into the /Frameworks folder of the ipa and are embedded. The frameworks themselves are static frameworks.... If you delete them from the xcarchive manually, everything works as expected.
Basically many of the answers here point to the right direction, but the problem remains because the solution is to remove the unwanted artifacts every single time. Currently (Jan 2021) AFAIK there is no other way to solve it.
pzs7602
Updated on November 28, 2021Comments
-
pzs7602 over 2 years
I have a Swift project that uses a ObjC dynamic framework, the framework had to be linked with and embedded into my project. The project runs OK in devices, when submitted to App Store, the error occurred during validation:
Found an unexpected Mach-O header code: 0x72613c21
Below are the validation logs:
2015-10-12 02:32:33 +0000 [MT] Beginning distribution assistant for archive: MusicFans, task: Validate 2015-10-12 02:32:33 +0000 [MT] Automatically selecting the only availaable distribution method <IDEDistributionMethodiOSAppStoreValidation: 0x7f851c1d96c0> 2015-10-12 02:32:34 +0000 [MT] [OPTIONAL] Didn't find archived user entitlements for <DVTFilePath:0x7f851b42db10:'/Users/panzhansheng/Library/Developer/Xcode/Archives/2015-10-11/MusicFans 11-10-15 上午8.29.xcarchive/Products/Applications/MusicFans.app/Frameworks/libswiftDispatch.dylib'>: Error Domain=NSCocoaErrorDomain Code=4 "Item at "/Users/panzhansheng/Library/Developer/Xcode/Archives/2015-10-11/MusicFans 11-10-15 上午8.29.xcarchive/Products/Applications/MusicFans.app/Frameworks/libswiftDispatch.dylib" did not contain a "archived-expanded-entitlements.xcent" resource." UserInfo={NSLocalizedDescription=Item at "/Users/panzhansheng/Library/Developer/Xcode/Archives/2015-10-11/MusicFans 11-10-15 上午8.29.xcarchive/Products/Applications/MusicFans.app/Frameworks/libswiftDispatch.dylib" did not contain a "archived-expanded-entitlements.xcent" resource.} 2015-10-12 02:32:34 +0000 [MT] [OPTIONAL] Didn't find archived user entitlements for <DVTFilePath:0x7f8529a08050:'/Users/panzhansheng/Library/Developer/Xcode/Archives/2015-10-11/MusicFans 11-10-15 上午8.29.xcarchive/Products/Applications/MusicFans.app/wavpack.framework'>: Error Domain=NSCocoaErrorDomain Code=4 "Item at "/Users/panzhansheng/Library/Developer/Xcode/Archives/2015-10-11/MusicFans 11-10-15 上午8.29.xcarchive/Products/Applications/MusicFans.app/wavpack.framework" did not contain a "archived-expanded-entitlements.xcent" resource." UserInfo={NSLocalizedDescription=Item at "/Users/panzhansheng/Library/Developer/Xcode/Archives/2015-10-11/MusicFans 11-10-15 上午8.29.xcarchive/Products/Applications/MusicFans.app/wavpack.framework" did not contain a "archived-expanded-entitlements.xcent" resource.} 2015-10-12 02:32:34 +0000 [MT] [OPTIONAL] Didn't find archived user entitlements for <DVTFilePath:0x7f850da13de0:'/Users/panzhansheng/Library/Developer/Xcode/Archives/2015-10-11/MusicFans 11-10-15 上午8.29.xcarchive/Products/Applications/MusicFans.app/FLAC.framework'>: Error Domain=NSCocoaErrorDomain Code=4 "Item at "/Users/panzhansheng/Library/Developer/Xcode/Archives/2015-10-11/MusicFans 11-10-15 上午8.29.xcarchive/Products/Applications/MusicFans.app/FLAC.framework" did not contain a "archived-expanded-entitlements.xcent" resource." UserInfo={NSLocalizedDescription=Item at "/Users/panzhansheng/Library/Developer/Xcode/Archives/2015-10-11/MusicFans 11-10-15 上午8.29.xcarchive/Products/Applications/MusicFans.app/FLAC.framework" did not contain a "archived-expanded-entitlements.xcent" resource.} 2015-10-12 02:33:07 +0000 [MT] Canceled distribution assistant
If I remove the dynamic framework from the project’s Embedded frameworks section, then it can pass the validation, but crashes when run in devices due to the missing image of my dynamic framework, any idea? BTW, dynamic framework has bitcode disabled, so my project also disables bitcode, and is not codesigned.
-
n13 over 8 yearsI did this - also did pod install - problem went away. Thanks this was quite brilliant.
-
Davie Brown over 8 yearsIn my case it was a file which was copied to the project. I removed this and the error disappeared. I then re-added the file and it seems to be fine now.
-
CodeOverRide about 8 yearsThanks! Glad it helped.
-
Thinker almost 8 yearsIf you click on the "Show log" button, and then look at the "verbose" logfile, you may see the name of the offending framework. At least it was there for me.
-
Adrian almost 8 yearsI tried the steps you outlined progressively and I got over the finish line when I uninstalled/downgraded cocoapods. Thank you!
-
Greg Brown over 7 yearsThat's not much of a "fix" if you actually need Fabric and Crashlytics (which I do).
-
Creagen about 7 yearsThank you! This was the problem in my case. I had Firebase in the Embedded Frameworks.
-
kokemomuke almost 7 yearsVery good explanation of dynamic and static libraries. 2 hours already searching
-
Chewie The Chorkie almost 6 yearsShould we assume that "Embeded Frameworks" is now equal to the section "Embedded Binaries"?
-
Chewie The Chorkie almost 6 yearsI don't understand. The FacebookSDK's frameworks are dynamic, so shouldn't they be in "embed frameworks"?
-
Bob de Graaf over 5 yearsThis answer should be the accepted answer. @pzs7602 accept it? :)
-
Cosyn over 5 years@ChewieTheChorkie I'm not sure. But it seems that all embed frameworks also appear in embedded binaries.
-
David Crow over 5 yearsYou should ensure you don't need the frameworks to be embedded (copied into the Frameworks folder) else you will get a dylib not found exception when you try to run on a device. This can be deceptive because it will work fine on the simulator.
-
Petrus Theron about 5 yearsWhat should the Mach-O type be for an iOS app, "Executable"?
-
Cosyn about 5 years@PetrusTheron Yes
-
Admin almost 5 yearsThanks, this works for me. I'm using Xcode
Version 10.3 (10G8)
. However I'm wondering if we still need to copy overFabric.framework
andCrashlytics.framework
. -
Jacob over 4 yearsI can't answer that question. But there is a run script that fabric requires you to add to your build scripts invoking
${PROJECT_DIR}/Carthage/Build/iOS/Fabric.framework/run
. My guess is that this is performing whatever needs to be done. -
Jan R. over 4 yearsThank you, this saved my day!
-
Darkwonder over 4 yearsWorks under Xcode Version 11.2.1 (11B500). I have read the logs and changed this for all my third party frameworks. Some "libSwift_XXX" frameworks also were repaired since they did not appear anymore after this change.
-
Adamski over 4 yearsThis results in a runtime error in my case
dyld: Library not loaded
-
firetrap about 4 yearsall my lib are "Do not embed" and still the same error.
-
Warpzit about 4 yearsThanks is not enough to express my gratitude.
-
Henry about 4 years+1 for this answer, basically in { App Target } -> Build Phases -> Copy Bundle Resources I deleted anything related to CocoaPods in there - made this issue go away
-
Ashley Mills almost 4 yearsThanks for the answer, but why is this the case? And which one (link or embed) should it be?
-
aiwis31 over 3 yearsThis is what worked for me (even if you're not using firebase). Actually this answer did not help me as it is, I found the solution in this comment precisely: github.com/firebase/firebase-ios-sdk/issues/…
-
Luca over 3 yearsThis also worked for me, I was using Firebase with SPM and a Widget, Thanks you!
-
user482594 over 3 yearsMake sure to select your app from
Provide build settings from [your_app_target]
in the select box. -
swifthing about 3 yearsSame as @Luca : using Firebase with SPM (without Widgets) and this also worked for me when archiving and uploading to AppSore. Thank you !
-
Krutika Sonawala almost 3 yearsdone. worked for me. you saved my day man!
-
TapulaRasa almost 3 yearsThanks fixed my issue
-
Shawn Frank over 2 yearsThanks a lot - this worked with Firebase using SPM !