Up to date

This page is up to date for Godot 4.2. If you still find outdated information, please open an issue.

為 iOS 匯出

也參考

這個頁面描述的是如何將 Godot 專案匯出到 iOS。如果你想要找的是從源碼編譯編輯器或匯出範本二進位檔案,請閱讀 為 iOS 進行編譯

下列步驟為在 Xcode 中載入 Godot 專案的方法。這些步驟能用來建置與部署專案至 iOS 裝置上、為 App Store 建置發行版本,並可在 Xcode 中執行各種其他一般操作。

注意

Projects written in C# can be exported to iOS as of Godot 4.2, but support is experimental and some limitations apply.

系統需求

  • 必須從有安裝 Xcode 的 macOS 電腦上為 iOS 匯出。

  • 下載 Godot 匯出樣板。使用 Godot 選單:[編輯器] > [管理匯出樣板]

匯出 Godot 專案至 Xcode

在 Godot 編輯器中,打開 [專案] 選單中的 [匯出] 視窗。[匯出] 視窗開啟後,點擊 [新增...] 然後選擇 [iOS]

必須設定下列匯出選項。將任何選項留空都會導致匯出工具拋出錯誤:

備註

如果您在匯出過程中遇到類似以下錯誤
“JSON 文字未以陣列或物件開頭,且未設定允許片段的選項”
那麼可能是由於 App Store 團隊 ID 格式錯誤!
匯出器需要一個(10 個字元長)程式碼,例如“ABCDE12XYZ”,而不是例如 Xcode 喜歡在“簽章和功能”標籤中顯示的您的姓名。
您可以在右上角您姓名旁的「developer.apple.com <https://developer.apple.com/account/resources/certificates/list>」找到程式碼。

點擊 [匯出專案] 後,還有兩個重要的選項要填:

  • [路徑] 為一個空資料夾,會用來儲存匯出後的 Xcode 專案檔案。

  • [檔案] 為 Xcode 專案的名稱,以及各種專案特定檔案與資料夾的名稱。

../../_images/ios_export_file.png

備註

本教學使用 exported_xcode_project_name ,但實際應該使用專案名稱。在接下來的步驟看到 exported_xcode_project_name 時,請自行替換。

備註

選擇 exported_xcode_project_name 時請避免使用空格,可能會導致 Xcode 專案檔案出錯。

匯出完成後,輸出資料夾應該長得像這樣:

../../_images/ios_export_output.png

開啟 exported_xcode_project_name.xcodeproj 即可像其他 iOS 應用程式一樣進行建置與部署。

活躍開發中的注意事項

上述方法能建立匯出專案,並用於建置發行版本,但每次於 Godot 中修改後都必須重新匯出。

開發時,可通過直接將 Godot 專案檔案串聯到應用程式中來加速這個過程。

在下方範例中:

  • exported_xcode_project_name 為匯出的 iOS 應用程式名稱 (如上)。

  • godot_project_to_export 為 Godot 專案名稱。

備註

godot_project_to_export 不可與 exported_xcode_project_name 相同,以避免 Xcode 上產生簽署問題。

為 iOS 進行編譯

Godot 中可使用特殊的 iOS 服務。請參考 doc_services_for_ios 一頁。

環境變數

您可以使用下列環境變數在編輯器外部設定匯出選項。在匯出過程中,這些值會覆寫您在匯出選單中設定的值。

環境變數

匯出選項

環境變數

加密/加密金鑰

GODOT_SCRIPT_ENCRYPTION_KEY

選項/應用程式/設定檔 UUID 偵錯

GODOT_IOS_PROVISIONING_PROFILE_UUID_DEBUG

選項/應用程式/設定檔 UUID 發布

GODOT_IOS_PROVISIONING_PROFILE_UUID_RELEASE

疑難排解

xcode-select points at wrong SDK location

xcode-select is a tool that comes with Xcode and among other things points at iOS SDKs on your Mac. If you have Xcode installed, opened it, agreed to the license agreement, and installed the command line tools, xcode-select should point at the right location for the iPhone SDK. If it somehow doesn't, Godot will fail exporting to iOS with an error that may look like this:

MSB3073: The command ""clang" <LOTS OF PATHS AND COMMAND LINE ARGUMENTS HERE>
"/Library/Developer/CommandLineTools/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk"" exited with code 1.

In this case, Godot is trying to find the Platforms folder containing the iPhone SDK inside the /Library/Developer/CommandLineTools/ folder, but the Platforms folder with the iPhone SDK is actually located under /Applications/Xcode.app/Contents/Developer. To verify this, you can open up Terminal and run the following command to see what xcode-select points at:

xcode-select -p

To fix xcode-select pointing at a wrong location, enter this command in Terminal:

sudo xcode-select -switch /Applications/Xcode.app

After running this command, Godot should be able to successfully export to iOS.