sudeepdino008
sudeepdino008

Reputation: 3364

xcodebuild archive failure: picking the wrong SDK?

I'm using fastlane to release an app. The simplified version of xcodebuild command to build the app is this:

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

This fails giving (adding a sample):

/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
 ^

I see that it's picking the MacOSX.sdk, I would expect it to pick iPhoneOS sdk present in Xcode directory. Is this the reason for failure? Or something else?

xcrun output:

» 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

Upvotes: 1

Views: 1522

Answers (2)

puio
puio

Reputation: 1278

Xcode is using the SDK in /Library/CommandLineTools. Instead, it should be using those inside Xcode app. Run

 xcode-select -r

or

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

Verify by

xcode-select -p

Some of them may need sudo.

Upvotes: 1

RY_ Zheng
RY_ Zheng

Reputation: 3427

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

In the 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. Use xcrun --sdk iphoneos --show-sdk-path to check the SDK path.
  2. Check the SDK you have in your Mac. In my Mac, there are iPhoneOS.sdk and iPhoneOS13.7.sdk
  • iPhoneOS13.7.sdk is a symbolic link and its origin is iPhoneOS.sdk .
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.7.sdk

Besides,

  • you can also use xcodebuild -showsdks to see all the sdks
  • Different parameter for different devices
    • iOS: -sdk iphoneos
    • Simulator: -sdk iphonesimulator
    • watchOS: -sdk watchos
    • macOS: -sdk macosx

Upvotes: 1

Related Questions