nil:NilClass 的 xcodebuild exportArchive 未定义方法小写

xcodebuild exportArchive undefined method downcase for nil:NilClass

我在尝试导出存档时看到此错误:

2017-03-08 16:33:01.413 xcodebuild[61048:2742229] [MT] IDEDistribution: Step failed: <IDEDistributionThinningStep: 0x7fe3d72312f0>: Error Domain=IDEDistributionErrorDomain Code=14 "No applicable devices found." UserInfo={NSLocalizedDescription=No applicable devices found.}
error: exportArchive: No applicable devices found.

Error Domain=IDEDistributionErrorDomain Code=14 "No applicable devices found." UserInfo={NSLocalizedDescription=No applicable devices found.}

我没有做任何应用瘦身:

<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>compileBitcode</key>
    <false/>
    <key>method</key>
    <string>enterprise</string>
    <key>teamID</key>
    <string>MYTEAMID</string>
    <key>thinning</key>
    <string>&lt;none&gt;</string>
    <key>uploadBitcode</key>
    <false/>
</dict>
</plist>

当我查看此处提到的目录时:

2017-03-21 08:47:20.275 xcodebuild[24493:1421657] [MT] IDEDistribution: -[IDEDistributionLogging _createLoggingBundleAtPath:]: Created bundle at path '/var/folders/36/28z3md3x08xcljbsh6tvv4xrcr93wf/T/UniversalFree_2017-03-21_08-47-20.274.xcdistributionlogs'.

我在 IDEDistribution.standard.log

中看到这个错误
2017-03-21 15:47:25 +0000  Scanning IPA...
2017-03-21 15:47:48 +0000  /Applications/Xcode-7.app/Contents/Developer/usr/bin/ipatool:2341:in `platformIdentifierForVersionMinLoadCommand': undefined method `downcase' for nil:NilClass (NoMethodError)
        from /Applications/Xcode-7.app/Contents/Developer/usr/bin/ipatool:1236:in `block in GetMachOImagesFromOToolInfoForFile'
        from /Applications/Xcode-7.app/Contents/Developer/usr/bin/ipatool:1196:in `each'
        from /Applications/Xcode-7.app/Contents/Developer/usr/bin/ipatool:1196:in `GetMachOImagesFromOToolInfoForFile'
        from /Applications/Xcode-7.app/Contents/Developer/usr/bin/ipatool:1294:in `MakeFileSystemNode'
        from /Applications/Xcode-7.app/Contents/Developer/usr/bin/ipatool:1322:in `block in MakeFileSystemNode'
        from /Applications/Xcode-7.app/Contents/Developer/usr/bin/ipatool:1321:in `each'
        from /Applications/Xcode-7.app/Contents/Developer/usr/bin/ipatool:1321:in `MakeFileSystemNode'
        from /Applications/Xcode-7.app/Contents/Developer/usr/bin/ipatool:1322:in `block in MakeFileSystemNode'
        from /Applications/Xcode-7.app/Contents/Developer/usr/bin/ipatool:1321:in `each'
        from /Applications/Xcode-7.app/Contents/Developer/usr/bin/ipatool:1321:in `MakeFileSystemNode'
        from /Applications/Xcode-7.app/Contents/Developer/usr/bin/ipatool:1085:in `initialize'
        from /Applications/Xcode-7.app/Contents/Developer/usr/bin/ipatool:1871:in `new'
        from /Applications/Xcode-7.app/Contents/Developer/usr/bin/ipatool:1871:in `ProcessIPA'
        from /Applications/Xcode-7.app/Contents/Developer/usr/bin/ipatool:2428:in `<main>'
2017-03-21 15:47:49 +0000 [MT] /Applications/Xcode-7.app/Contents/Developer/usr/bin/ipatool exited with 1

然后导出失败。我该如何处理?

回答我自己的问题,因为我在网上找不到直接的答案。虽然我不完全清楚是什么原因造成的,因为堆栈跟踪表明问题出现在 GetMachOImagesFromOToolInfoForFile 中的 ipatool 中。似乎期望它处理的每个项目的 loadCommands 都有一个 LC_VERSION_MIN_(.+) 形式的键,但似乎并非所有项目都是这种情况(如果有人可以确定原因并更新这个答案,非常感谢)。无论如何,您可以对ipatool到"fix"这个问题进行如下修改(新文件是左边的文件)。

TL/DR:编辑 /Applications/Xcode.app/Contents/Developer/usr/bin/ipatool

对于Xcode 7...

608,610d607
<     if (self.machoFile == nil)
<       return "<MachOImage nil #{self.arch}>"
<     end
1239,1242d1235
<     if (versionMinLoadCommandName == nil)
<       next
<     end
1302c1295
<       if (machoImages && machoImages.length > 0)
---
>       if machoImages

而对于 Xcode 8...

750,752d749
<     if (self.machoFile == nil)
<       return "<MachOImage nil #{self.arch}>"
<     end

1438,1440d1434
<     if (versionMinLoadCommandName == nil)
<       next
<     end
1510c1504
<       if (machoImages && machoImages.length > 0)
---
>       if machoImages