exporting_for_android.rst 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. .. _doc_exporting_for_android:
  2. Exporting for Android
  3. =====================
  4. .. seealso::
  5. This page describes how to export a Godot project to Android.
  6. If you're looking to compile export template binaries from source instead,
  7. read :ref:`doc_compiling_for_android`.
  8. Exporting for Android has fewer requirements than compiling Godot for Android.
  9. The following steps detail what is needed to set up the Android SDK and the engine.
  10. .. attention::
  11. Projects written in C# can be exported to Android as of Godot 4.2, but support
  12. is experimental and :ref:`some limitations apply <doc_c_sharp_platforms>`.
  13. Install OpenJDK 17
  14. ------------------
  15. Download and install `OpenJDK 17 <https://adoptium.net/temurin/releases/?variant=openjdk17&version=17&os=any&arch=any>`__.
  16. .. note::
  17. Higher versions of the JDK are also supported, but we recommend using JDK 17 for optimal compatibility and stability.
  18. Download the Android SDK
  19. ------------------------
  20. Download and install the Android SDK.
  21. - You can install the Android SDK using `Android Studio Iguana (version 2023.2.1) or later <https://developer.android.com/studio/>`__.
  22. - Run it once to complete the SDK setup using these `instructions <https://developer.android.com/studio/intro/update#sdk-manager>`__.
  23. - Ensure that the `required packages <https://developer.android.com/studio/intro/update#required>`__ are installed as well.
  24. - Android SDK Platform-Tools version 35.0.0 or later
  25. - Android SDK Build-Tools version 35.0.0
  26. - Android SDK Platform 35
  27. - Android SDK Command-line Tools (latest)
  28. - Ensure that the `NDK and CMake are installed and configured <https://developer.android.com/studio/projects/install-ndk>`__.
  29. - CMake version 3.10.2.4988404
  30. - NDK version r28b (28.1.13356709)
  31. - Alternatively, you can install the Android SDK with the `sdkmanager` command line tool.
  32. - Install the command line tools package using these `instructions <https://developer.android.com/tools/sdkmanager>`__.
  33. - Once the command line tools are installed, run the following `sdkmanager` command to complete the setup process:
  34. ::
  35. sdkmanager --sdk_root=<android_sdk_path> "platform-tools" "build-tools;35.0.0" "platforms;android-35" "cmdline-tools;latest" "cmake;3.10.2.4988404" "ndk;28.1.13356709"
  36. .. note::
  37. If you are using Linux,
  38. **do not use an Android SDK provided by your distribution's repositories as it will often be outdated**.
  39. Setting it up in Godot
  40. ----------------------
  41. Enter the Editor Settings screen (under the Godot tab for macOS, or the Editor tab
  42. for other platforms). This screen contains the editor settings for the user
  43. account in the computer (it's independent of the project).
  44. .. image:: img/editorsettings.png
  45. Scroll down to the section where the Android settings are located:
  46. .. image:: img/android_editor_settings.webp
  47. In that screen, 2 paths need to be set:
  48. - ``Java SDK Path`` should be the location where OpenJDK 17 was installed.
  49. - ``Android Sdk Path`` should be the location where the Android SDK was installed.
  50. - For example ``%LOCALAPPDATA%\Android\Sdk\`` on Windows or ``/Users/$USER/Library/Android/sdk/`` on macOS.
  51. Once that is configured, everything is ready to export to Android!
  52. .. note::
  53. If you get an error saying *"Could not install to device."*, make sure
  54. you do not have an application with the same Android package name already
  55. installed on the device (but signed with a different key).
  56. If you have an application with the same Android package name but a
  57. different signing key already installed on the device, you **must** remove
  58. the application in question from the Android device before exporting to
  59. Android again.
  60. Providing launcher icons
  61. ------------------------
  62. 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.
  63. There are three types of icons:
  64. - **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.
  65. - **Adaptive Icons:** Starting from Android 8 (inclusive), `Adaptive Icons <https://developer.android.com/guide/practices/ui_guidelines/icon_design_adaptive>`_ 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.
  66. - **Themed Icons (optional):** Starting from Android 13 (inclusive), Themed Icons were introduced. Applications will need to include a monochrome icon to enable this feature. The user's launcher application will control the icon's theme. Must be at least 432×432 px.
  67. .. seealso:: It's important to adhere to some rules when designing adaptive icons. `Google Design has provided a nice article <https://medium.com/google-design/designing-adaptive-icons-515af294c783>`_ that helps to understand those rules and some of the capabilities of adaptive icons.
  68. .. caution:: 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.
  69. If you don't provide the requested icons (except for Monochrome), Godot will replace them using a fallback chain, trying the next in line when the current one fails:
  70. - **Main Icon:** Provided main icon -> Project icon -> Default Godot main icon.
  71. - **Adaptive Icon Foreground:** Provided foreground icon -> Provided main icon -> Project icon -> Default Godot foreground icon.
  72. - **Adaptive Icon Background:** Provided background icon -> Default Godot background icon.
  73. It's highly recommended to provide all the requested icons with their specified resolutions.
  74. This way, your application will look great on all Android devices and versions.
  75. Exporting for Google Play Store
  76. -------------------------------
  77. All new apps uploaded to Google Play after August 2021 must be an AAB (Android App Bundle)
  78. file.
  79. Uploading an AAB or APK to Google's Play Store requires you to sign using a non-debug
  80. keystore file; such a file can be generated like this:
  81. .. code-block:: shell
  82. keytool -v -genkey -keystore mygame.keystore -alias mygame -keyalg RSA -validity 10000
  83. This keystore and key are used to verify your developer identity, remember the password and keep it in a safe place!
  84. It is suggested to use only upper and lowercase letters and numbers. Special characters may cause errors.
  85. Use Google's Android Developer guides to learn more about `app signing <https://developer.android.com/studio/publish/app-signing>`__.
  86. Now fill in the following forms in your Android Export Presets:
  87. .. image:: img/editor-export-presets-android.png
  88. - **Release:** Enter the path to the keystore file you just generated.
  89. - **Release User:** Replace with the key alias.
  90. - **Release Password:** Key password. Note that the keystore password and the key password currently have to be the same.
  91. Don't forget to uncheck the **Export With Debug** checkbox while exporting.
  92. .. image:: img/export-with-debug-button.png
  93. Optimizing the file size
  94. ------------------------
  95. If you're working with APKs and not AABs, by default, the APK will contain native
  96. libraries for both ARMv7 and ARMv8 architectures. This increases its size significantly.
  97. To create a smaller file, uncheck either **Armeabi-v 7a** or **Arm 64 -v 8a** in
  98. your project's Android export preset. This will create an APK that only contains
  99. a library for a single architecture. Note that applications targeting ARMv7 can
  100. also run on ARMv8 devices, but the opposite is not true. The reason you don't do
  101. this to save space with AABs is that Google automatically splits up the AAB on their
  102. backend, so the user only downloads what they need.
  103. You can optimize the size further by compiling an Android export template with
  104. only the features you need. See :ref:`doc_optimizing_for_size` for more
  105. information.
  106. Environment variables
  107. ---------------------
  108. You can use the following environment variables to set export options outside of
  109. the editor. During the export process, these override the values that you set in
  110. the export menu.
  111. .. list-table:: Android export environment variables
  112. :header-rows: 1
  113. * - Export option
  114. - Environment variable
  115. * - Encryption / Encryption Key
  116. - ``GODOT_SCRIPT_ENCRYPTION_KEY``
  117. * - Options / Keystore / Debug
  118. - ``GODOT_ANDROID_KEYSTORE_DEBUG_PATH``
  119. * - Options / Keystore / Debug User
  120. - ``GODOT_ANDROID_KEYSTORE_DEBUG_USER``
  121. * - Options / Keystore / Debug Password
  122. - ``GODOT_ANDROID_KEYSTORE_DEBUG_PASSWORD``
  123. * - Options / Keystore / Release
  124. - ``GODOT_ANDROID_KEYSTORE_RELEASE_PATH``
  125. * - Options / Keystore / Release User
  126. - ``GODOT_ANDROID_KEYSTORE_RELEASE_USER``
  127. * - Options / Keystore / Release Password
  128. - ``GODOT_ANDROID_KEYSTORE_RELEASE_PASSWORD``
  129. Export options
  130. --------------
  131. You can find a full list of export options available in the
  132. :ref:`class_EditorExportPlatformAndroid` class reference.