Attention: Here be dragons
This is the latest
(unstable) version of this documentation, which may document features
not available in or compatible with released stable versions of Godot.
Checking the stable version of the documentation...
为 iOS 平台编译
参见
本页面描述的是如何从源码编译 iOS 编辑器和导出模板二进制文件。如果你想要将项目导出到 iOS,请移步《为 iOS 导出》。
需求
SCons 4.4+ 构建系统。
- Xcode。
启动一次 Xcode 并安装 iOS 支持。如果你已经安装了 Xcode 后需要安装 iOS 支持,转到 Xcode -> Settings... -> Platforms 。
转到 Xcode -> Settings... -> Locations -> Command Line Tools 选择一个安装的版本。即使已经选择了一个版本,也需要重新选择它。
下载 MoltenVK SDK ,并按照其 README 文档中的说明,构建一个静态的
.xcframework。
编译
打开终端,进入引擎源代码的根目录,然后输入以下内容来编译一个调试(debug)版本:
scons platform=ios target=template_debug generate_bundle=yes
编译发布构建:
scons platform=ios target=template_release generate_bundle=yes
如果你想创建一个像官方发布版那样的 Xcode 项目,需要使用位于 misc/dist/ios_xcode 目录下的模板。Release(发布)和 Debug(调试)版本的库文件,应分别放入 libgodot.ios.debug.xcframework 和 libgodot.ios.release.xcframework 文件夹中。这个过程可以通过在构建导出模板时使用的 最后 一条 SCons 命令中添加 generate_bundle=yes 选项来自动完成(这样就能把所有的二进制文件都包含进去了)。
一旦创建完成,MoltenVK 的静态 .xcframework 文件夹也必须被放入 ios_xcode 文件夹中。在 iOS 平台上,MoltenVK 始终采用静态链接;与 macOS 不同,iOS 上并没有提供动态链接的选项。
警告
iOS 模拟器仅支持 兼容 渲染器。
搭载 Apple Silicon 芯片的 Mac 电脑可以原生运行 iOS 应用,因此你可以直接在 Apple Silicon Mac 上运行导出的 iOS 项目,而完全不受 iOS 模拟器的各种限制。
运行
如果你想在真机设备上运行,请按照这里的说明进行操作: 为 iOS 导出。
导出的 iOS 项目其实可以直接在搭载 Apple 芯片(Apple Silicon)的 Mac 上运行。如果你想在 Mac 上直接测试导出的 iOS 项目,只需要用 Xcode 打开该项目,然后在顶部的‘运行目标’( Run Destinations )下拉菜单里,选择 My Mac 就可以了。
故障排除
致命错误:找不到 'cstdint' 文件
如果你在编译刚开始不久就遇到了这种形式的报错,很可能是因为你的 macOS 系统或 Xcode 刚刚更新过,导致 Xcode 命令行工具的安装需要修复一下:
./core/typedefs.h:45:10: fatal error: 'cstdint' file not found
45 | #include <cstdint>
| ^~~~~~~~~
运行这两条命令来重新安装 Xcode 命令行工具(如果需要的话,请输入你的管理员密码):
sudo rm -rf /Library/Developer/CommandLineTools
sudo xcode-select --install
如果还是不行,可以尝试从 Mac App Store 更新 Xcode,然后再试一次。