为Android导出

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

下载Android SDK

Download and install the Android SDK.

  1. sdkmanager --sdk_root=<android_sdk_path> "platform-tools" "build-tools;30.0.1" "platforms;android-29" "cmdline-tools;latest"

Install OpenJDK

Download and install OpenJDK.

创建一个debug.keystore

Android needs a debug keystore file to install to devices and distribute non-release APKs. If you have used the SDK before and have built projects, ant or eclipse probably generated one for you (in the ~/.android directory on Linux and macOS, in the C:\Users\<user>\.android\ directory on Windows).

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

  1. 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

这会在当前目录中创建一个``debug.keystore`` 文件。你需要移动到一个难忘的位置,比如 %USERPROFILE%\.android\,因为后续步骤会需要这个位置。keytool 用法的更多信息请查看`这个 Q&A 文章 <https://godotengine.org/qa/21349/jdk-android-file-missing>`__。

在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

In that screen, 2 paths need to be set:

  • The Android Sdk Path should be the location where the Android SDK was installed. - For example %LOCALAPPDATA%\Android\Sdk\ on Windows or /Users/$USER/Library/Android/sdk/ on macOS.
  • debug .keystore``文件 - 可以在之前创建 ``debug.keystore 文件的文件夹中找到。

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

提供启动器图标

启动图标是Android启动器应用把你的应用展示给用户时用到的。Godot只需要高分辨率图标(适用于``xxxhdpi``屏幕),然后自动生成低分辨率变体。

Godot需要两种类型的图标:

  • Main Icon: “经典” 图标。这会在所有Android版本不高于 Android 8 (Oreo)中使用。必须至少 192×192 px.
  • Adaptive Icons: 从 Android 8 (包括)开始, Adaptive Icons 被引入。应用为了有原生的样式需要包含分离的背景与前景图标。用户的启动程序会控制图标的动画和遮罩。必须至少432×432 px。

参见

重要的是设计自适应图标时必须遵守一些规则。Google Design 提供了一篇文章 来帮助理解这些规则以及自适应图标的一些技巧。

警告

最重要的自适应图标规则是,把图标的重要元素放置在安全区:一个直径为66dp(``xxxhdpi``上为264像素)居中的圆来避免被启动器裁剪。

如果你不提供必要的图标,Godot会用备用链来替换它们,当当前行失败时会尝试下一行:

  • 主图标: 提供主图标 -> 项目图标 -> 默认Godot主图标。
  • 自适应图标前景: 提供的前景图标 ->提供的主图标 -> 项目图标 -> 默认 Godot 前景图标。
  • 自适应图标背景: 提供的背景图标 -> 默认 Godot 背景图标。

强烈推荐提供必需的图标,至少是指定的分辨率。只有这样,你的应用才能在所有Android设备和版本看起来不错。

为Google Play商店导出

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

  1. 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导出模板来进一步优化大小。有关更多信息,请参见 为尺寸优化构建