xcodebuild存档失败:选择错误的SDK?

问题描述

我正在使用Fastlane发布应用程序。用于构建应用程序的xcodebuild命令的简化版本是这样的:

xcodebuild -workspace App.xcworkspace -scheme App 
           -configuration Release -sdk iphoneos13.6 
           -destination 'generic/platform=iOS' clean archive

这无法给出(添加示例):

/Library/Developer/CommandLinetools/SDKs/MacOSX.sdk/usr/include/sys/cdefs.h:807:2: error: Unsupported architecture
#error Unsupported architecture
 ^
In file included from /Users/sudeepkumar/Zendrive/mobile-apps/ios/copilot/Pods/glog/src/symbolize.cc:55:
In file included from /Users/sudeepkumar/Zendrive/mobile-apps/ios/copilot/Pods/glog/src/utilities.h:73:
In file included from /Users/sudeepkumar/Zendrive/mobile-apps/ios/copilot/Pods/glog/src/base/mutex.h:141:
In file included from /Library/Developer/CommandLinetools/SDKs/MacOSX.sdk/usr/include/pthread.h:55:
In file included from /Library/Developer/CommandLinetools/SDKs/MacOSX.sdk/usr/include/_types.h:27:
In file included from /Library/Developer/CommandLinetools/SDKs/MacOSX.sdk/usr/include/sys/_types.h:33:
/Library/Developer/CommandLinetools/SDKs/MacOSX.sdk/usr/include/machine/_types.h:34:2: error: architecture not supported
#error architecture not supported
 ^

我看到它正在选择MacOSX.sdk,我希望它会选择Xcode目录中存在的iPhoneOS sdk。这是失败的原因吗?还是其他?

xcrun输出

» xcrun --show-sdk-platform-path
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform

» xcrun --sdk iphoneos --show-sdk-platform-path
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform

解决方法

Xcode正在/Library/CommandLineTools中使用SDK。相反,它应该在Xcode应用程序内部使用它们。运行

 xcode-select -r

xcode-select -s "/Applications/Xcode.app/Contents/Developer"

验证人

xcode-select -p

其中一些人可能需要sudo

,
xcodebuild -workspace App.xcworkspace -scheme App 
           -configuration Release -sdk iphoneos
           -destination 'generic/platform=iOS' clean archive

xcodebuild man page

-sdk [<sdkfullpath> | <sdkname>]
           Build an Xcode project or workspace against the specified SDK,using build tools appropriate for that SDK. The argument may be an
           absolute path to an SDK,or the canonical name of an SDK.
  1. 使用xcrun --sdk iphoneos --show-sdk-path检查SDK路径。
  2. 检查Mac中的SDK。在我的Mac中,有iPhoneOS.sdkiPhoneOS13.7.sdk
  • iPhoneOS13.7.sdk是一个符号链接,其起源是iPhoneOS.sdk
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.7.sdk

此外,

  • 您还可以使用xcodebuild -showsdks查看所有sdks
  • 不同设备的不同参数
    • iOS:-sdk iphoneos
    • 模拟器:-sdk iphonesimulator
    • watchOS:-sdk watchos
    • macOS:-sdk macosx