exporting_for_android.rst 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. .. _doc_exporting_for_android:
  2. Exporting for Android
  3. =====================
  4. Exporting for Android has fewer requirements than compiling Godot for Android.
  5. The following steps detail what is needed to set up the Android SDK and the engine.
  6. Download the Android SDK
  7. ------------------------
  8. Download and install the Android SDK.
  9. - You can install it using `Android Studio version 4.1 or later <https://developer.android.com/studio/>`__.
  10. - Run it once to complete the SDK setup using these `instructions <https://developer.android.com/studio/intro/update#sdk-manager>`__.
  11. - Ensure that the `required packages <https://developer.android.com/studio/intro/update#recommended>`__ are installed as well.
  12. - Android SDK Platform-Tools version 30.0.5 or later
  13. - Android SDK Build-Tools version 30.0.3
  14. - Android SDK Platform 29
  15. - Android SDK Command-line Tools (latest)
  16. - CMake version 3.10.2.4988404
  17. - NDK version 21.4.7075529
  18. - You can install it using the `command line tools <https://developer.android.com/studio/#command-tools>`__.
  19. - Once the command line tools are installed, run the `sdkmanager <https://developer.android.com/studio/command-line/sdkmanager>`__ command to complete the setup process:
  20. ::
  21. sdkmanager --sdk_root=<android_sdk_path> "platform-tools" "build-tools;30.0.3" "platforms;android-29" "cmdline-tools;latest" "cmake;3.10.2.4988404" "ndk;21.4.7075529"
  22. .. note::
  23. If you are using Linux,
  24. **do not use an Android SDK provided by your distribution's repositories as it will often be outdated**.
  25. Install OpenJDK 11
  26. ------------------
  27. Download and install `OpenJDK 11 <https://adoptium.net/?variant=openjdk11>`__.
  28. Create a debug.keystore
  29. -----------------------
  30. Android needs a debug keystore file to install to devices and distribute
  31. non-release APKs. If you have used the SDK before and have built
  32. projects, ant or eclipse probably generated one for you (in the ``~/.android`` directory on Linux and
  33. macOS, in the ``C:\Users\<user>\.android\`` directory on Windows).
  34. If you can't find it or need to generate one, the keytool command from
  35. the JDK can be used for this purpose::
  36. 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
  37. 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 <https://godotengine.org/qa/21349/jdk-android-file-missing>`__.
  38. Setting it up in Godot
  39. ----------------------
  40. Enter the Editor Settings screen. This screen contains the editor
  41. settings for the user account in the computer (it's independent of the
  42. project).
  43. .. image:: img/editorsettings.png
  44. Scroll down to the section where the Android settings are located:
  45. .. image:: img/androidsdk.png
  46. In that screen, 2 paths need to be set:
  47. - The ``Android Sdk Path`` should be the location where the Android SDK was installed.
  48. - For example ``%LOCALAPPDATA%\Android\Sdk\`` on Windows or ``/Users/$USER/Library/Android/sdk/`` on macOS.
  49. - The debug ``.keystore`` file
  50. - It can be found in the folder where you put the ``debug.keystore`` file you created above.
  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 two types of icons required by Godot:
  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. .. 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.
  67. .. 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.
  68. 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:
  69. - **Main Icon:** Provided main icon -> Project icon -> Default Godot main icon.
  70. - **Adaptive Icon Foreground:** Provided foreground icon -> Provided main icon -> Project icon -> Default Godot foreground icon.
  71. - **Adaptive Icon Background:** Provided background icon -> Default Godot background icon.
  72. It's highly recommended to provide all the requested icons with their specified resolutions.
  73. This way, your application will look great on all Android devices and versions.
  74. Exporting for Google Play Store
  75. -------------------------------
  76. Uploading an APK to Google's Play Store requires you to sign using a non-debug
  77. keystore file; such file can be generated like this:
  78. .. code-block:: shell
  79. keytool -v -genkey -keystore mygame.keystore -alias mygame -keyalg RSA -validity 10000
  80. This keystore and key are used to verify your developer identity, remember the password and keep it in a safe place!
  81. Use Google's Android Developer guides to learn more about `APK signing <https://developer.android.com/studio/publish/app-signing>`__.
  82. Now fill in the following forms in your Android Export Presets:
  83. .. image:: img/editor-export-presets-android.png
  84. - **Release:** Enter the path to the keystore file you just generated.
  85. - **Release User:** Replace with the key alias.
  86. - **Release Password:** Key password. Note that the keystore password and the key password currently have to be the same.
  87. **Your export_presets.cfg file now contains sensitive information.** If you use
  88. a version control system, you should remove it from public repositories and add
  89. it to your ``.gitignore`` file or equivalent.
  90. Don't forget to uncheck the **Export With Debug** checkbox while exporting.
  91. .. image:: img/export-with-debug-button.png
  92. Optimizing the APK size
  93. -----------------------
  94. By default, the APK will contain native libraries for both ARMv7 and ARMv8
  95. architectures. This increases its size significantly. To create a smaller APK,
  96. uncheck either **Armeabi-v 7a** or **Arm 64 -v 8a** in your project's Android
  97. export preset. This will create an APK that only contains a library for
  98. a single architecture. Note that applications targeting ARMv7 can also run on
  99. ARMv8 devices, but the opposite is not true.
  100. Since August 2019, Google Play requires all applications to be available in
  101. 64-bit form. This means you cannot upload an APK that contains *just* an ARMv7
  102. library. To solve this, you can upload several APKs to Google Play using its
  103. `Multiple APK support <https://developer.android.com/google/play/publishing/multiple-apks>`__.
  104. Each APK should target a single architecture; creating an APK for ARMv7
  105. and ARMv8 is usually sufficient to cover most devices in use today.
  106. You can optimize the size further by compiling an Android export template with
  107. only the features you need. See :ref:`doc_optimizing_for_size` for more
  108. information.