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

🌈

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

43 Answers

βœ”οΈAccepted Answer

YuAo
183

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

Other Answers:

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

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

Looks like this has been fixed in Xcode 8 beta 3 πŸŽ‰

More Issues: