# 使用其他 Xcode 版本建置 App

> 在雲端團隊中，詢問 Agent 可以用哪些 Xcode 版本建置，並請它用你選的版本建置 App 或執行測試。

Source: https://air.build/tw/docs/build/build-with-a-different-xcode-version/

在雲端團隊中，你的 App 是在雲端的 Mac 建置機上建置的。建置機有多種環境，每種環境都有自己的 macOS 和 Xcode 版本。除非 Agent 指定了其他環境，建置都會使用預設環境。你可以要求改用其他環境，例如確認 App 仍能用較舊的 Xcode 建置，或試用較新的版本。Agent 透過 [runmacos](https://air.build/tw/docs/cli/runmacos/) 在 Mac 建置機上執行的其他腳本，也可以用同樣的方式選擇環境。

> [!NOTE]
> 本頁適用於雲端團隊。本機團隊使用其 Mac 上的 Xcode 建置：請參閱[本機團隊](https://air.build/tw/docs/build/build-with-a-different-xcode-version/#in-a-local-team)。AirBuild 沒有設定 Xcode 版本的選項。你在專案的聊天中請 Agent 處理，它會使用 `runbuild --list-environments` 和 `runbuild --environment`（請參閱 [runbuild](https://air.build/tw/docs/cli/runbuild/)）。在建置機上，建置腳本會透過 [airbuild-xcode](https://air.build/tw/docs/cli/airbuild-xcode/) 執行 Xcode。

## 查看可用的版本

在專案的聊天中提問，例如：

```text
Which Xcode versions can you build with?
```

1. Agent 執行 `runbuild --list-environments`。
2. 它會告訴你找到的每個環境：名稱以及 macOS 和 Xcode 版本。預設環境排在最前面。

本頁不列出具體版本。每次你詢問時，Agent 都會讀取目前的列表。

## 用你選的版本建置

說出你想要的版本，例如：

```text
Build the app with the oldest Xcode on that list and put it in Preview.
```

1. Agent 用 `--environment` 加上你選的環境開始建置。說明表示，在其他環境上建置可能需要更長時間才會開始。
2. 建置完成後，它和其他建置沒有差別。要在預覽中打開它，請點一下 **重新安裝**（在 iPhone 上則點一下 App 的圖像）。請參閱[在預覽中執行你的 App](https://air.build/tw/docs/build/preview-your-app/#use-the-device)。
3. 如果建置失敗，Agent 會告訴你原因，你可以請它針對該 Xcode 修正專案。

說明是這樣寫的：「It picks what the app is built with, not where it runs.」（它選擇的是用什麼建置 App，而不是 App 在哪裡執行。）預覽裝置維持不變。要在其他裝置上試用 App，請在預覽的裝置選單中選擇：請參閱[在預覽中執行你的 App](https://air.build/tw/docs/build/preview-your-app/#choose-a-device)。

## 用於測試或簽署建置

Agent 執行 App 的測試時，以及為 TestFlight 和 App Store 進行簽署建置時，同樣可以這樣選擇。在提出要求時說出版本，例如：

```text
Run the tests with the newest Xcode you have.
```

執行測試請參閱[讓 Agent 執行 App 的測試](https://air.build/tw/docs/build/run-your-apps-tests/)。簽署建置請參閱[用 TestFlight 分享 Beta 版](https://air.build/tw/docs/app-store/test-with-testflight/)。

## 之後的建置

這個選擇只對一次建置有效。專案不會記住它：Agent 發起的每次建置，只要沒有指定環境，都會使用預設環境。想再次使用那個版本時，每次要求建置都要說出它。

## 本機團隊

本機團隊使用其 Mac 上的 Xcode 建置，所以沒有可供選擇的列表。要用其他版本建置，請更換那台 Mac 上的 Xcode。AirBuild 的 **設定這台 Mac** 會顯示目前使用的版本；缺少 Xcode 時，它提供的解決方法是在 **Xcode ▸ 設定 ▸ 位置 ▸ Command Line Tools** 中選擇一個。請參閱[選擇 Agent 的執行位置](https://air.build/tw/docs/get-started/where-agents-run/#set-up-your-mac-for-a-local-team)。

## 常見問題

**Agent 說建置機環境只屬於雲端團隊。**

訊息是「Builder environments belong to cloud Teams; this Team builds with the Xcode on its owning Mac.」（建置機環境屬於雲端團隊；此團隊使用其所屬 Mac 上的 Xcode 建置。）你的團隊是本機團隊。請參閱[本機團隊](https://air.build/tw/docs/build/build-with-a-different-xcode-version/#in-a-local-team)。

**Agent 說 --environment 需要列表中的 ID。**

訊息是「--environment takes an id from `runbuild --list-environments`.」（--environment 需要取自該列表的 ID。）Agent 沒有給這個選項提供環境的 ID。請它重新列出環境，並用其中一個環境的 ID 建置。

**這會改變 Xcode Cloud 使用的 Xcode 嗎？**

不會。Xcode Cloud 工作流程在 **環境** 下有自己的 **Xcode** 和 **macOS** 版本。請參閱[使用 Xcode Cloud 建置](https://air.build/tw/docs/app-store/build-with-xcode-cloud/#create-a-workflow)。

**可以用不在列表中的 Xcode 建置嗎？**

在雲端團隊中不行：建置只會使用列出的某個環境。在本機團隊中，使用的是 Mac 本身的 Xcode。
