Thursday, November 16, 2023

_NativeStripFiles fails when building release build to upload Apple Store

I do not know if this is relatively known. This xcode-select --switch command.

Anyway, this is what happened to me. As it took sometime for me to figure this out. It is probably worth taking note.

First of all, I had multiple instances of Xcode installed on my Mac.

To be more precise, I have got a new Mac recently, a few months back. By then, the latest Xcode was 15. Naturally, I installed it.

Then I found that Visual Studio (I develop a Xamarin app) of that moment does not work hand-in-hand with Xcode15. I installed Xcode 14.3, keeping 15. They are sitting in different folders. In Visual Studio, I specify 14.3 as Apple SDK.

All went well. I built and published my app with the 16.4 SDK which comes with Xcode 14.3.

Sometime after that, I felt the need of using 17 SDK (I wrongly believed that this is required to support iOS17 devices). I found that with the Visual Studio update out in Oct 2023, I can use Xcode15 SDK (which is 17.0). The new build runs OK on an iOS17 simulator. So far so good.

To release to App Store, we need to build the app against an actual device, as you know. Then I have got this error:

xcrun: error: sh -c '/Applications/Xcode_14.3.1.app/Contents/Developer/usr/bin/xcodebuild ...

What?! Why this still tries a command of Xcode14.3, even after I have switched the Apple SDK to use to Xcode15!

I looked everywhere, Googled for a hint. No chance.

Helpless, I told myself how happens if I removed the Xcode14.3 installation folder.

Bingo! Now the error has changed and saying:

xcode-select: note: No developer tools were found, requesting install.

If developer tools are located at a non-default location on disk, use `sudo xcode-select --switch path/to/Xcode.app` to specify the Xcode that you wish to use for command line developer tools

With this message, I have come to know that I need to run the command to tell the system the Xocde I want to use.