Cocoapods: [Xcode 8 beta 2]: CopySwiftLibs for Pods framework fails with Mach-O header error

Created on 6 Jul 2016  路  42Comments  路  Source: CocoaPods/CocoaPods

馃寛

Report

When attempting to build my project using Xcode 8 beta 2, it fails to build with a Found an unexpected Mach-O header code: 0x72613c21 error during the CopySwiftLibs /Users/jshier/Library/Developer/Xcode/DerivedData/ValidationTest-gtjgwrjygnilcneuhsknzgpuuhun/Build/Products/Debug-iphonesimulator/Pods_ValidationTest.framework step. This has been seen before when there's a signing issue, however, this project worked fine in beta 1. Perhaps something about the new framework signing is an issue now? Even when I set the project to not sign and then build for the 6s simulator I get the same error.

What did you do?

Ran the build step in Xcode 8 beta 2 (10.11.5).

What did you expect to happen?

Successful build.

What happened instead?

Build failure, as described.

CocoaPods Environment

Gemfile

source "https://rubygems.org"

gem "cocoapods", :git => 'https://github.com/CocoaPods/CocoaPods.git'
gem "xcodeproj", :git => 'https://github.com/CocoaPods/Xcodeproj.git'
gem 'cocoapods-downloader', :git => 'https://github.com/CocoaPods/cocoapods-downloader.git'
gem 'cocoapods-core', :git => 'https://github.com/CocoaPods/Core.git'
gem 'activesupport', '~> 4.2.6'

Stack

   CocoaPods : 1.0.1
        Ruby : ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin15]
    RubyGems : 2.5.1
        Host : Mac OS X 10.11.5 (15F34)
       Xcode : 8.0 (8S162m)
         Git : git version 2.8.4 (Apple Git-73)
Ruby lib dir : /Users/jshier/.rvm/rubies/ruby-2.3.1/lib
Repositories : detroit-labs-specs - https://github.com/detroit-labs/detroit-labs-specs.git @ 90fd1ac1e0b30403afd5ea66b6353d058267efdd
               master - https://github.com/CocoaPods/Specs.git @ 7f933b66717e5e7c8fa100c2d8804af119b2f820

Installation Source

Executable Path: /Users/jshier/.rvm/gems/ruby-2.3.1@unexpectedmachoheader/bin/pod

Plugins

cocoapods-deintegrate : 1.0.0
cocoapods-plugins     : 1.0.0
cocoapods-search      : 1.0.0
cocoapods-stats       : 1.0.0
cocoapods-trunk       : 1.0.0
cocoapods-try         : 1.0.0

Podfile

platform :ios, '10.0'

target 'ValidationTest' do

  use_frameworks!

 pod 'Alamofire', git: "https://github.com/Alamofire/Alamofire.git", branch: "swift3"

end

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      if config.name != 'Debug'
        config.build_settings['SWIFT_OPTIMIZATION_LEVEL'] = '-Owholemodule'
      else
        config.build_settings['SWIFT_OPTIMIZATION_LEVEL'] = '-Onone'
      end
    end
  end
end

Project that demonstrates the issue

https://github.com/jshier/unexpectedMachOHeader.git

Most helpful comment

I've found a workaround.

Add the following lines to your Podfile:

post_install do |installer|
    installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
            config.build_settings['ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES'] = 'NO'
        end
    end
end

All 42 comments

This doesn't appear to be a localized issue because I and a few other people seems to have this same bug? too. I can confirm that a clean, brand new project with a basic empty pod still fails on my end.

Ever so glad I didn't empty my trash yet so I've still got Xcode 8b1

I can confirm this issue too. Been battling it for the past 4 hours.

@shusain93 Send me 尾1 lol, I overwrote mine like a rookie!

@joeblau found a master list at stackoverflow. Downloads straight from Apple

http://stackoverflow.com/a/10335943/1166266

Here's the link I pulled out that worked for me

I've found a workaround.

Add the following lines to your Podfile:

post_install do |installer|
    installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
            config.build_settings['ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES'] = 'NO'
        end
    end
end

The workaround suggested by @YuAo is probably a solution for the following change mentioned in the Xcode 8 beta 2 Release Notes

The new build setting ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES replaces the use of EMBEDDED_CONTENT_CONTAINS_SWIFT. This setting indicates that Xcode should always embed Swift standard libraries in a target for which it has been set, whether or not the target contains Swift code. A typical scenario for using this setting is when a target directly uses or embeds another product which contains Swift code.

Note: EMBEDDED_CONTENT_CONTAINS_SWIFT has been deprecated. (26158130)

I think I have the same error in Xcode 8 beta 2 but I am doing the pod trunk push. Everything worked in Xcode 8 beta 1.

How to reproduce

git clone https://github.com/evgenyneu/moa.git
cd moa
pod spec lint --verbose

Errors

builtin-swiftStdLibTool --copy --verbose --sign - --scan-executable /Users/evgenii/Library/Developer/Xcode/DerivedData/App-ebjrdwhkfktfbpdpiconxeiufnsp/Build/Products/Release-appletvsimulator/Pods_App.framework/Pods_App --scan-folder /Users/evgenii/Library/Developer/Xcode/DerivedData/App-ebjrdwhkfktfbpdpiconxeiufnsp/Build/Products/Release-appletvsimulator/Pods_App.framework/Frameworks --scan-folder /Users/evgenii/Library/Developer/Xcode/DerivedData/App-ebjrdwhkfktfbpdpiconxeiufnsp/Build/Products/Release-appletvsimulator/Pods_App.framework/PlugIns --scan-folder /Applications/Xcode-beta2.app/Contents/Developer/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS9.2.sdk/System/Library/Frameworks/Foundation.framework --platform appletvsimulator --destination /Users/evgenii/Library/Developer/Xcode/DerivedData/App-ebjrdwhkfktfbpdpiconxeiufnsp/Build/Products/Release-appletvsimulator/Pods_App.framework/Frameworks --strip-bitcode --resource-destination /Users/evgenii/Library/Developer/Xcode/DerivedData/App-ebjrdwhkfktfbpdpiconxeiufnsp/Build/Products/Release-appletvsimulator/Pods_App.framework --resource-library libswiftRemoteMirror.dylib
error: Found an unexpected Mach-O header code: 0x72613c21

** BUILD FAILED **


The following build commands failed:
    CopySwiftLibs /Users/evgenii/Library/Developer/Xcode/DerivedData/App-ebjrdwhkfktfbpdpiconxeiufnsp/Build/Products/Release-appletvsimulator/Pods_App.framework
(1 failure)
 -> moa (5.0.0)
    - ERROR | xcodebuild: Returned an unsuccessful exit code.
    - NOTE  | xcodebuild:  error: Found an unexpected Mach-O header code: 0x72613c21

Analyzed 1 podspec.

[!] The spec did not pass validation, due to 1 error.

Note the path to the framework: /Users/evgenii/Library/Developer/Xcode/DerivedData/App-ebjrdwhkfktfbpdpiconxeiufnsp/Build/Products/Release-appletvsimulator/Pods_App.framework. The file is called Pods_App.framework, but there is no such file there, there is one called moa.framework. Not sure if that's the cause of the problem but it looks suspicious.

Stack

   CocoaPods : 1.0.1
        Ruby : ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-darwin14]
    RubyGems : 2.4.5
        Host : Mac OS X 10.11.5 (15F34)
       Xcode : 8.0 (8S162m)
         Git : git version 2.8.4 (Apple Git-73)
Ruby lib dir : /Users/evgenii/.rbenv/versions/2.2.2/lib
Repositories : master - https://github.com/CocoaPods/Specs.git @ d6e93d25b62310e4559aad53fbe6c0cbd474a0bf

Installation Source

Executable Path: /Users/evgenii/.rbenv/versions/2.2.2/bin/pod

Plugins

cocoapods-deintegrate : 1.0.0
cocoapods-plugins     : 1.0.0
cocoapods-search      : 1.0.0
cocoapods-stats       : 1.0.0
cocoapods-trunk       : 1.0.0
cocoapods-try         : 1.0.0

Something's broken in xcode's copy swift std lib step.

I can reproduce with an empty, new project on Xcode 8 and linking the crashlytics framework, without even using cocoa pods.
Filed http://www.openradar.me/radar?id=5045072026402816 tonight.

I also have the exact same issue on beta2 and confirmed that @YuAo fix does work for me.

What worked for me was I selected the Pods target and then changed "Embedded Content Contains Swift" to NO, even though there IS a swift-based pod among my pods. "Always Embed Swift Standard Libraries" was already set to NO. Thanks to everyone for contributing on this issue!

screen shot 2016-07-06 at 11 07 45 am

@iOSSoftwareEngineer Yes, it appears that that old setting, set at the Pods-Project framework level overrides the new default of NO for ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES. @YuAo's workaround sets that setting explicitly at the framework level and so overrides the ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES setting.

@olarivain Thanks for filing the radar, I suspected this was a general bug in beta 2, but couldn't quite get a repro case without CP together last night.

Finally managed to do pod trunk push with Xcode 8 beta 2 by adding a hack

settings['ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES'] = 'NO'

to custom_build_settings method in file lib/cocoapods/installer/target_installer.rb.

I couldn't get @YuAo's workaround to work no matter how I set it in the pod file. When I followed as @iOSSoftwareEngineer had said and set EMBEDDED_CONTENT_CONTAINS_SWIFT = NO it built perfectly.

Not sure if this helps. Fresh pod project with no bells and whistles in Xcode 8b2.

I had the same issue and tried many different methods. Eventually I solved the issue by clicking on the pod_YOURAPPNAME target, then going to build settings. Then under linking beside Mach-O Type change it from static to Dynamic Library.

@torinpitchers This also did it for me (after changing EMBEDDED_CONTENT_CONTAINS_SWIFT back to YES).

@torinpitchers - this was the last sticking point for getting our app to build under Xcode 8 before release. Mainly so we could profile the app using the lasted profiling tools highlighted in one of the WWDC 2016 videos. Changing from static to Dynamic Library was a magical fix. Thanks!

Please keep in mind that changing the product type of the aggregate target to dynamic might break deployment. Changing the ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES build setting seems like the preferable workaround for the meantime.

Nothing helped,Still looking for a better solution

My radar has been closed as a dupe last night. Doesn't mean they'll actually fix it (though they usually do for Xcode), but at least they're aware of it :)

I'm trying to do a pod spec lint on a Swift project in Xcode 8 beta 2 (migrated to Swift 3), using cocoapods 1.1.0 beta 1, but I'm getting the Found an unexpected Mach-O header code: 0x72613c21 error on the CopySwiftLibs command.

I have tried the post install to set the ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = 'NO', and tried setting the pod targets to be dynamic libraries. Also tried setting EMBEDDED_CONTENT_CONTAINS_SWIFT = 'NO' but nothing works so far :(

@emmaleechoon I don't think there is any workaround for linting right now, because that generates its own project as part of the process and that will not pick up any modifications you might do to the example project or its Podfile.

Ok thanks @neonichu, will just have to hold off on adding it to our podspecs repo

Looks like this has been fixed in Xcode 8 beta 3 馃帀

I still get this error on Xcode 8 beta 3 and nothing works:(

It works fine for me, so I'd suggest clearing your derived data, doing a pod install and then trying again.

I've tried all the aforementioned suggestions and had zero success fixing this.. Running Xcode 8 beta 3

I have temporarily disabled Fabric(crashlytics) in a new target to at least be able to work until a solution comes out, to be noted that I wasn't using Fabric through cocoapods but it was loading the embeded binary, so not sure if it is cocoapods related issue, it was working fine for me on XCode 8 beta 1, now I am on beta 3

Sounds like there is still an issue with integrating prebuilt static binaries, like Fabric, but the original issue regarding the aggregate static library CocoaPods uses doesn't exist anymore with beta 3.

I currently don't see a way to affect the issue with prebuilt static binaries from the CocoaPods side, so I'd encourage everyone experiencing it to file radars.

Not working with Xcode 8 beta 3.

Also experiencing this issue, and none of the aforementioned solutions work for me.

However, I do not see any EMBEDDED_CONTENT_CONTAINS_SWIFT = 'NO' in my pods target. I can only see ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = 'NO'

Any follow up on this topic? It seems some of us are still experiencing this issue.

I have tried all solutions posted here and still encountering the same issues for Xcode 8 Beta-3.

I hope people read this thread from top to bottom. It reminds me of a social experiment for monkeys. For entertainment, here's a rather amusing one

Switch ON -> Switch OFF -> Switch ON

Some guy even put EMBEDDED_CONTENT_CONTAINS_SWIFT back to its original YES state and got it working.

PS not calling anyone a monkey here. I'm just pointing out that this is all ludicrous, and its best to wait for fix from Apple (if it is indeed Xcode 8 bug) or proper implementation from Cocoapods if Apple decides change their convention.

"Found an unexpected Mach-O header code: 0x72613c21" is fixed with Xcode 8 Beta 4. Just verified it, I am able to compile the app now.

me too :)

Xcode 8 Beta 4 fixed it.

I created a completely new project in Xcode 8.1 and I get the same ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES warning.

Looks like this might be fixed in 1.2.0.beta.1. Have you tried it? But this issue isn't about that.

Oh, didn't know it wasn't released yet. Any idea how to install the beta version with brew?

I'm not sure how you'd install it with brew. But you should be able to do gem install cocoapods --pre to get it

Can confirm that on Xcode Version 8.1 (8B62), 1.2.0.beta.1 has removed the ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES warning.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pallaviMN picture pallaviMN  路  3Comments

intelliot picture intelliot  路  3Comments

lzwjava picture lzwjava  路  3Comments

pronebird picture pronebird  路  3Comments

hmistry picture hmistry  路  3Comments