为Android导出

为Android导出比为Android编译Godot的要求更少。以下步骤详细说明了设置SDK和引擎所需的内容。

下载Android SDK

Download and install the Android SDK from developer.android.com.

If you install Android Studio, you need to run it once to complete the SDK setup.

Install OpenJDK 8

Download and install OpenJDK 8, newer versions do not work.

创建一个debug.keystore

Android需要调试密钥库文件,才能安装到设备并分发非发布版本APK。如果您以前使用过SDK并且已经构建了项目,那么ant或eclipse可能会为您生成一个(在Linux和macOS上,您可以在 〜/ .android 目录中找到它)。

If you can't find it or need to generate one, the keytool command from the JDK can be used for this purpose:

keytool -keyalg RSA -genkeypair -alias androiddebugkey -keypass android -keystore debug.keystore -storepass android -dname "CN=Android Debug,O=Android,C=US" -validity 9999 -deststoretype pkcs12

This will create a debug.keystore file in your current directory. You should move it to a memorable location such as %USERPROFILE%\.android\, because you will need its location in a later step. For more information on keytool usage, see this Q&A article.

确保您有adb

Android Debug Bridge (adb) is the command line tool used to communicate with Android devices. It's installed with the SDK, but you may need to install one (any) of the Android API levels for it to be installed in the SDK directory.

在Godot中设置它

Enter the Editor Settings screen. This screen contains the editor settings for the user account in the computer (it's independent of the project).

../../../_images/editorsettings.png

向下滚动到Android设置所在的部分:

../../../_images/androidsdk.png

在该界面中,需要设置3个文件的路径:

  • The adb executable (adb.exe on Windows) - It can usually be found at %LOCALAPPDATA%\Android\Sdk\platform-tools\adb.exe.
  • The jarsigner executable (from JDK 6 or 8) - On Windows, OpenJDK installs to a directory like %PROGRAMFILES%\AdoptOpenJDK\jdk-8.0.252.09-hotspot\bin. On Linux, it typically installs to a directory like /usr/bin/jarsigner. The exact path may vary depending on the OpenJDK update you've installed and your machine's operating system.
  • The debug .keystore file - It can be found in the folder where you put the debug.keystore file you created above.

配置完成后,导出到Android的一切都准备好了!

提供启动器图标

Launcher icons are used by Android launcher apps to represent your application to users. Godot only requires high-resolution icons (for xxxhdpi density screens) and will automatically generate lower-resolution variants.

There are two types of icons required by Godot:

  • Main Icon: The "classic" icon. This will be used on all Android versions up to Android 8 (Oreo), exclusive. Must be at least 192×192 px.
  • Adaptive Icons: Starting from Android 8 (inclusive), Adaptive Icons were introduced. Applications will need to include separate background and foreground icons to have a native look. The user's launcher application will control the icon's animation and masking. Must be at least 432×432 px.

参见

It's important to adhere to some rules when designing adaptive icons. Google Design has provided a nice article that helps to understand those rules and some of the capabilities of adaptive icons.

警告

The most important adaptive icon design rule is to have your icon critical elements inside the safe zone: a centered circle with a diameter of 66dp (264 pixels on xxxhdpi) to avoid being clipped by the launcher.

If you don't provide some of the requested icons, Godot will replace them using a fallback chain, trying the next in line when the current one fails:

  • Main Icon: Provided main icon -> Project icon -> Default Godot main icon.
  • Adaptive Icon Foreground: Provided foreground icon -> Provided main icon -> Project icon -> Default Godot foreground icon.
  • Adaptive Icon Background: Provided background icon -> Default Godot background icon.

It's highly recommended to provide all requested icons, and at least with the specified resolutions. Only this way your application will look great on all Android devices and versions.

为Google Play商店导出

将APK上传到Google的Play商店,需要您使用非调试密钥库文件进行签名,这样的文件可以像这样生成:

keytool -v -genkey -v -keystore mygame.keystore -alias mygame -keyalg RSA -validity 10000

此密钥库和密钥用于验证您的开发人员身份,记住密码并将其保存在安全的地方!使用Google的Android开发者指南来了解有关 APK签名 的更多信息。

现在,在您的Android导出预设中填写以下表格:

../../../_images/editor-export-presets-android.png
  • 发布: 输入您刚刚生成的密钥库文件的路径。
  • 发布用户: 替换为密钥别名。
  • 发布密码: 密钥密码。 请注意,密钥库密码和密钥密码当前必须相同。

您的export_presets.cfg文件现在包含敏感信息。 如果使用版本控制系统,则应将其从公共存储库中删除,并将其添加到 .gitignore 文件或等效文件中。

选择APK的名称时,请不要忘记取消选中 带调试导出 复选框。

../../../_images/export-with-debug-button.png

优化APK大小

默认情况下,APK将包含适用于ARMv7和ARMv8体系结构的本地库。这会大大增加其大小。要创建较小的APK,请在项目的Android导出预设中取消选中 Armeabi-v 7aArm 64 -v 8a。这将创建一个仅包含单个架构库的APK。请注意,针对ARMv7的应用程序也可以在ARMv8设备上运行,但事实并非如此。

自2019年8月起,Google Play要求所有应用程序都必须以64位格式提供。这意味着您不能上传 包含ARMv7库的APK。为了解决这个问题,您可以使用其 多个APK支持 将多个APK上传到Google Play。每个APK都应针对单一架构;为ARMv7和ARMv8创建APK通常足以覆盖当今使用的大多数设备。

您可以通过仅编译具有所需功能的Android导出模板来进一步优化大小。有关更多信息,请参见 为尺寸优化构建