iosxcodenativescript

Set path to xcodebuild for NativeScript CLI commands to enforce a specific version of XCode


On my Mac, there are several versions of Xcode installed. I found out that XCode 14 does not seem to be compatible with my NativeScript 8.4.* project, because the XCode workspace that is being generated by ns prepare ios fails to build in XCode 14. However, in XCode 13.4.1, building the same XCode workspace and deploying it to the iPhone simulator works without issues.

So, in order to be able to use the NativeScript commands like ns run ios instead of having to manually open the generated XCode workspace in XCode, I wanted to force the NativeScript CLI to use the XCode 13.4.1 CLI tools. I opened the terminal and set an alias like alias xcodebuild=/Applications/Xcode13.4.1.app/Contents/Developer/usr/bin/xcodebuild before running the NativeScript CLI, but NativeScript seems to ignore that alias.

When I run xcodebuild -version before setting the alias, it returns version 14.x. After setting my alias, the same command returns (as desired) version 13.4.1. However, running ns doctor ios after having set my alias, it still tells me that it found XCode 14...

How can I force the NativeScript CLI to use a specific path/version of xcodebuild?


Solution

  • I found out that changing the PATH for my current session does the trick:

    ns doctor ios before doing anything tells me Xcode version 14.3.1 satisfies minimum required version 10..

    I then prepend the path to my desired XCode installation to the PATH: export PATH=/Applications/Xcode13.4.1.app/Contents/Developer/usr/bin:$PATH, and voila, NativeScript is now using my desired installation of Xcode, because ns doctor ios now says Xcode version 13.4.1 satisfies minimum required version 10. and other commands like ns run ios work properly instead of giving me build errors.

    However, I don't feel like this is a very elegant solution. If anybody knows a more elegant way, I am open to other answers.