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 的 mac OS的计算机中为 iOS 导出。

  • 下载 Godot 导出模板。请使用 Godot 菜单:编辑器 > 管理导出模板

将 Godot 项目导出到 Xcode

在 Godot 编辑器中,从项目菜单打开导出窗口。导出窗口打开后,点击添加.. 并选择 iOS

应用分类中的 App Store 团队 ID 和(捆绑包)标识符选项都是必填的。留空时导出器会报错。

备注

If you encounter an error during export similar to
JSON text did not start with array or object and option to allow fragments not set
then it might be due to a malformated App Store Team ID!
The exporter expects a (10 characters long) code like ABCDE12XYZ and not, e.g., your name as Xcode likes to display in the Signing & Capabilities tab.
You can find the code over at developer.apple.com next to your name in the top right corner.

点击导出项目后,仍有两个重要选项:

  • 路径是一个空文件夹,它将包含导出的 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_exportexported_xcode_project_name 必须不一样, 以免Xcode出现签名问题.

iOS 的插件

在 Godot 中可以使用特殊的 iOS 插件。请查看 iOS 的插件 页面。

环境变量

你可以使用以下环境变量在编辑器外部设置导出选项。在导出过程中,这些值会覆盖你在导出菜单中设置的值。

iOS 导出环境变量

导出选项

环境变量

加密 / 密钥

GODOT_SCRIPT_ENCRYPTION_KEY

Options / Application / Provisioning Profile UUID Debug

GODOT_IOS_PROVISIONING_PROFILE_UUID_DEBUG

Options / Application / Provisioning Profile UUID Release

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.