Found an unexpected Mach-O header code: 0x72613c21 in Xcode 7

52,172

Solution 1

Check two things for every framework:

  1. The Mach-O type of the framework (in Build Settings of the framework target)

Mach-O

  1. Whether you copy the framework by putting it in Build Phases -> Embed Frameworks (or Copy Bundle Resources as mentioned by a. brooks hollar)

Embed frameworks

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.

enter image description here

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"

enter image description here

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.

Share:
52,172
pzs7602
Author by

pzs7602

Updated on November 28, 2021

Comments

  • pzs7602
    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
    n13 over 8 years
    I did this - also did pod install - problem went away. Thanks this was quite brilliant.
  • Davie Brown
    Davie Brown over 8 years
    In 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
    CodeOverRide about 8 years
    Thanks! Glad it helped.
  • Thinker
    Thinker almost 8 years
    If 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
    Adrian almost 8 years
    I tried the steps you outlined progressively and I got over the finish line when I uninstalled/downgraded cocoapods. Thank you!
  • Greg Brown
    Greg Brown over 7 years
    That's not much of a "fix" if you actually need Fabric and Crashlytics (which I do).
  • Creagen
    Creagen about 7 years
    Thank you! This was the problem in my case. I had Firebase in the Embedded Frameworks.
  • kokemomuke
    kokemomuke almost 7 years
    Very good explanation of dynamic and static libraries. 2 hours already searching
  • Chewie The Chorkie
    Chewie The Chorkie almost 6 years
    Should we assume that "Embeded Frameworks" is now equal to the section "Embedded Binaries"?
  • Chewie The Chorkie
    Chewie The Chorkie almost 6 years
    I don't understand. The FacebookSDK's frameworks are dynamic, so shouldn't they be in "embed frameworks"?
  • Bob de Graaf
    Bob de Graaf over 5 years
    This answer should be the accepted answer. @pzs7602 accept it? :)
  • Cosyn
    Cosyn over 5 years
    @ChewieTheChorkie I'm not sure. But it seems that all embed frameworks also appear in embedded binaries.
  • David Crow
    David Crow over 5 years
    You 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
    Petrus Theron about 5 years
    What should the Mach-O type be for an iOS app, "Executable"?
  • Cosyn
    Cosyn about 5 years
    @PetrusTheron Yes
  • Admin
    Admin almost 5 years
    Thanks, this works for me. I'm using Xcode Version 10.3 (10G8). However I'm wondering if we still need to copy over Fabric.framework and Crashlytics.framework.
  • Jacob
    Jacob over 4 years
    I 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.
    Jan R. over 4 years
    Thank you, this saved my day!
  • Darkwonder
    Darkwonder over 4 years
    Works 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
    Adamski over 4 years
    This results in a runtime error in my case dyld: Library not loaded
  • firetrap
    firetrap about 4 years
    all my lib are "Do not embed" and still the same error.
  • Warpzit
    Warpzit about 4 years
    Thanks is not enough to express my gratitude.
  • Henry
    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
    Ashley Mills almost 4 years
    Thanks for the answer, but why is this the case? And which one (link or embed) should it be?
  • aiwis31
    aiwis31 over 3 years
    This 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
    Luca over 3 years
    This also worked for me, I was using Firebase with SPM and a Widget, Thanks you!
  • user482594
    user482594 over 3 years
    Make sure to select your app from Provide build settings from [your_app_target] in the select box.
  • swifthing
    swifthing about 3 years
    Same as @Luca : using Firebase with SPM (without Widgets) and this also worked for me when archiving and uploading to AppSore. Thank you !
  • Krutika Sonawala
    Krutika Sonawala almost 3 years
    done. worked for me. you saved my day man!
  • TapulaRasa
    TapulaRasa almost 3 years
    Thanks fixed my issue
  • Shawn Frank
    Shawn Frank over 2 years
    Thanks a lot - this worked with Firebase using SPM !