- 安装多个Xcode,可以在Xcode下载页面查询下载各个版本的Xcode,下载安装
- 需要注意的是下载解压后的XCode放入指定的目录,需要注意命名,如果使用XCode15.x这种命名,在编译时有可能出现swiftheader的编译问题,swiftbridge相关的头文件无法查询,根据分析,只能在XCode.app/Content下才能索引,所以使用哪个XCode,就应该将它命名为XCode.app
- 使用Xcode-select进行当前Xcode的选择
-可以通过Xcode-select和xcodebuild指令来确认切换是否成功
Xcode-select -p
gcc --version
xcodebuild -version
网上也有用脚本实现的,但基于XCode命名问题,编译可能出现问题
change_xcode_version()
{
[ "$1" != "11" -a "$1" != "13" ] && echo "input is $1,not 11 or 13" && exit 1
xcode_v=$1
echo "xcode version:"
xcodebuild -version
[ "$1" == "11" ] && export DEVELOPER_DIR=/Applications/Xcode/11.4/Xcode.app/Contents/Developer
[ "$1" == "13" ] && export DEVELOPER_DIR=/Applications/Xcode/13.1/Xcode.app/Contents/Developer
./expect_xcode $1 # 调用切换Xcode版本的脚本
sleep 10
xcodebuild -version
# 检查DEVELOPER_DIR是否切换成功,否则异常退出
xcode_ver=`xcodebuild -version |grep Xcode |awk -F " " '{print $2}'`
[ "$1" == "11" ] && [ "$xcode_ver" != "11.4" ] && echo "xcode version $xcode_ver, not 11.4" && exit 1
[ "$1" == "13" ] && [ "$xcode_ver" != "13.1" ] && echo "xcode version $xcode_ver, not 13.1" && exit 1
echo "new xcode version:"
xcodebuild -version
}
#!/usr/bin/expect
set timeout 10
set version [lindex $argv 0]
set password "123456" # 开机密码
if {$version == "13" } {
spawn sudo xcode-select -s /Applications/Xcode/13.1/Xcode.app/Contents/Developer
}
if {$version == "11" } {
spawn sudo xcode-select -s /Applications/Xcode/11.4/Xcode.app/Contents/Developer
}
expect "*assword*" {send "$password\r"} # 自动输入密码
interact