一键部署

什么是一键部署?

平台配置正确并且将支持的设备连接到电脑上之后,就可以使用一键部署功能。因为能出错的地方太多了(平台可能没有配置正确、SDK 可能没有正确安装、设备可能配置错了等等),所以最好让用户先知道有这样的功能。

添加 Android 导出预设项并且标记为可执行之后,Godot 就可以检测到有 USB 设备插到了电脑上,并且允许用户在该设备上自动导出、安装、然后运行(调试模式的)项目。这个功能就叫 一键部署

备注

在导出对话框中添加导出模板并标记为可执行后便可使用一键部署。你可以同时将多个导出预设项标记为可执行,但同一平台被标记为可执行的只能有一个。如果你把该平台的第二个预设项标记为可执行,其它预设项的标记会被取消。

支持的平台

  • Android: 将在导出项目时启用调试,并在连接的设备上运行。

    • 请确认已经按照 为 Android 导出 中提到的步骤进行操作,否则不会出现一键部署按钮。

    • 如果你连接的设备超过一台,Godot会询问你想导出项目到哪台设备。

  • iOS: Exports the project with debugging enabled and runs it on the connected device or simulator.

    • Make sure to follow the steps described in 为 iOS 导出. Otherwise, the one-click deploy button won’t appear.

    • For each new bundle identifier, export the project, open it in the Xcode, and build at least once to create new provisioning profile or create a provisioning profile in the Apple Developer account dashboard.

    • 如果你连接的设备超过一台,Godot会询问你想导出项目到哪台设备。

  • Desktop platforms: Exports the project with debugging enabled and runs it on the remote computer via SSH.

  • Web: Starts a local web server and runs the exported project by opening the default web browser. This is only accessible on localhost by default. See Troubleshooting for making the exported project accessible on remote devices.

使用一键部署

  • Android:

    • Enable developer mode on your mobile device then enable USB debugging in the device’s settings.

    • After enabling USB debugging, connect the device to your PC using a USB cable.

    • 如果你是高级用户,也可以使用无线ADB。

  • iOS:

    • Install Xcode, accept Xcode license and login with your Apple Developer account.

    • If you are using Xcode 14 or earlier, install ios-deploy and set path to ios-deploy in the Editor Settings (see Export ⇾ iOS ⇾ iOS Deploy).

    • For running on device:

      • Pair your mobile device with a Mac.

      • Enable developer mode on your device.

      • Device can be connected via USB or local network.

      • Make sure the device is on the same local network and a correct network interface is selected in the editor settings (see Network ⇾ Debug ⇾ Remote Host). By default, the editor is listening for localhost connections only.

  1. - For running in simulator:
  2. - Install and start simulator from the Xcode.
  3. - Device screen should be unlocked.
  • Desktop platforms:

    • Enable SSH Remote Deploy and configure connection settings in the project export setting.
  • Make sure there is an export preset marked as Runnable for the target platform (Android, iOS or Web).

  • 如果这些都配置正确并且没有报错,编辑器右上角会出现平台对应的图标。

  • 点击该按钮一键导出到所需的平台。

../../_images/remote_debug.webp

故障排除

Android

如果你在命令行中运行 adb devices 时无法在设备列表中看到该设备,那么 Godot 就也无法看到。要解决这个问题:

  • 请检查是否启用了 USB 并在该设备上授权。请尝试解锁你的设备,如果有任何授权的弹框的话请接受。如果你没有看到这样的弹框,在 PC 上执行 adb devices 应该就会在该设备上弹出授权提示。

  • 请尝试在该设备的开发者设置中撤销调试授权,然后再重试这些步骤。

  • 请尝试使用 USB 调试而不是无线调试,反之亦然。有时候换种方法就能更好地工作。

  • 在 Linux 上,你可能缺少所需的 udev 规则,导致你的设备无法被识别。

Web

By default, the web server started by the editor is only accessible from localhost. This means the web server can’t be reached by other devices on the local network or the Internet (if port forwarding is set up on the router). This is done for security reasons, as you may not want other devices to be able to access the exported project while you’re testing it. Binding to localhost also prevents a firewall popup from appearing when you use one-click deploy for the web platform.

To make the local web server accessible over the local network, you’ll need to change the Export > Web > HTTP Host editor setting to 0.0.0.0. You will also need to enable Export > Web > Use TLS as SharedArrayBuffer requires the use of a secure connection to work, unless connecting to localhost. However, since other clients will be connecting to a remote device, the use of TLS is absolutely required here.

To make the local web server accessible over the Internet, you’ll also need to forward the Export > Web > HTTP Port port specified in the Editor Settings (8060 by default) in TCP on your router. This is usually done by accessing your router’s web interface then adding a NAT rule for the port in question. For IPv6 connections, you should allow the port in the router’s IPv6 firewall instead. Like for local network devices, you will also need to enable Export > Web > Use TLS.

备注

When Use TLS is enabled, you will get a warning from your web browser as Godot will use a temporary self-signed certificate. You can safely ignore it and bypass the warning by clicking Advanced and then Proceed to (address).

If you have an SSL/TLS certificate that is trusted by browsers, you can specify the paths to the key and certificate files in the Export > Web > TLS Key and Export > Web > TLS Certificate. This will only work if the project is accessed through a domain name that is part of the TLS certificate.