xcodebuild export archive fails with cryptic exception

I'm trying to export an iOS app archive using xcodebuild from Xcode 13.1, but the export is failing with the following exception:

$ xcodebuild -exportArchive -exportOptionsPlist exportPlist.plist -archivePath [REDACTED] -exportPath build/ 

2021-11-01 11:52:03.141 xcodebuild[2234:1268877] [MT] IDEDistribution: -[IDEDistributionLogging _createLoggingBundleAtPath:]: Created bundle at path "/var/folders/y0/9yktphk14bj_rfljxbhbd40c0000gn/T/[REDACTED]".
2021-11-01 11:52:34.646 xcodebuild[2234:1268877] -[NSNull path]: unrecognized selector sent to instance 0x7fff80701eb0
** INTERNAL ERROR: Uncaught exception **
Uncaught Exception: -[NSNull path]: unrecognized selector sent to instance 0x7fff80701eb0
Stack:
  0   __exceptionPreprocess (in CoreFoundation)
  1   objc_exception_throw (in libobjc.A.dylib)
  2   -[NSObject(NSObject) __retain_OA] (in CoreFoundation)
  3   ___forwarding___ (in CoreFoundation)
  4   _CF_forwarding_prep_0 (in CoreFoundation)
  5   -[IDEDistributionProcessingPipeline process:] (in IDEFoundation)
  6   -[IDEDistributionPackagingStep loadFromExportOptions:error:] (in IDEFoundation)
  7   -[IDEDistributionDriver runWithDestinationPath:error:] (in IDEFoundation)
  8   -[Xcode3CommandLineBuildTool _distributeArchiveAndExit] (in Xcode3Core)
  9   -[Xcode3CommandLineBuildTool run] (in Xcode3Core)
 10   main (in xcodebuild)
 11   start (in libdyld.dylib)

[1]    2234 abort      xcodebuild -exportArchive -exportOptionsPlist fastlane/exportPlist.plist   
Answered by fjcaetano2 in 695460022

The bug was introduced in our project because one of our dependencies is not ready to use bitcode. Disabling bitcode on Xcode was solving the issue, but using the xcodebuild command was not, because we tried using an export options plist file generated by Fastlane, which seems to be defective.

Be sure to disable bitcode when exporting your archived build. If you're using xcodebuild ensure your export options plist includes the following entry:

<key>compileBitcode</key>
<false/>

If you're using Fastlane, the include_bitcode: false argument seems to have no effect in the final export options plist generated by Fastlane. Instead use the following argument on gym/build_ios_app:

export_options: {
  compileBitcode: false,
}

Please refer to this issue in the Fastlane repository, if necessary: https://github.com/fastlane/fastlane/issues/19550

I am experiencing the exact same issue. Xcode 13.1 is crashing with this error message when attempting to export our iOS app from the archive.

We have the same problem, but only on our ARM Macs. Intel based system are working fine.

I'm seeing this in an Intel Mac running Big Sur (11.5.2)

We started migrating some of our projects lately from Cocoapods to SwiftPM, and faced exactly the same issue. Took many hours since the stacktrace was not giving enough information, and using reductio ad absurdum I managed to locate a problematic Swift Package (in my case it was the UIColor-Hex-Swift package). Weirdly enough, this issue is occurring only when used as Swift Package and not as a Cocoapods Dependency.

I managed to solve this issue by getting the 13.2 beta version and attempting to export the archive. Fortunately the crash was fixed but there was an error thrown by the IPA Tool.

When looking into the error logs provided I managed to see that it was complaining about finding duplicate symbols. Which helped me to resolve the problems within our project settings. Essentially there were some frameworks being embedded in our dependent modules which should have been using the “Do not embed” option.

After that I was able to archive and export the build on Xcode 13.1 again. So it seems that Xcode 13.1 has a bug where potentially any error thrown during the distribution phase will just crash the app.

Accepted Answer

The bug was introduced in our project because one of our dependencies is not ready to use bitcode. Disabling bitcode on Xcode was solving the issue, but using the xcodebuild command was not, because we tried using an export options plist file generated by Fastlane, which seems to be defective.

Be sure to disable bitcode when exporting your archived build. If you're using xcodebuild ensure your export options plist includes the following entry:

<key>compileBitcode</key>
<false/>

If you're using Fastlane, the include_bitcode: false argument seems to have no effect in the final export options plist generated by Fastlane. Instead use the following argument on gym/build_ios_app:

export_options: {
  compileBitcode: false,
}

Please refer to this issue in the Fastlane repository, if necessary: https://github.com/fastlane/fastlane/issues/19550

xcodebuild export archive fails with cryptic exception
 
 
Q