android_custom_build.rst 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. .. _doc_android_custom_build:
  2. Custom builds for Android
  3. =========================
  4. Godot provides the option to use custom build Android templates. Instead of
  5. using the already pre-built template that ships with Godot, an actual Android
  6. Java project gets installed into your project folder. Godot will then build it
  7. and use it as an export template every time you export the project.
  8. There are some reasons why you may want to do this:
  9. * Modify the project before it's built.
  10. * Add external SDKs that build with your project.
  11. Configuring the custom build is a more or less straightforward process,
  12. but it may take a while to get used to how the Android SDK works.
  13. Instructions will be provided as detailed as possible to do this process.
  14. Set up the custom build environment
  15. -----------------------------------
  16. Go to the Project menu, and install the *Custom Build* template:
  17. .. image:: img/custom_build_install_template.png
  18. Make sure export templates are downloaded. If not, this menu will help you
  19. download them.
  20. This will create an Gradle-based Android project in ``res://android/build`` and
  21. place a ``.gdignore`` file in ``res://android`` so the Godot filesystem ignores
  22. this folder. Editing these files is not needed unless you want to :ref:`create
  23. your own add-ons<doc_android_plugin>`, or you really need to modify the project.
  24. Install the Android SDK (command-line version)
  25. ----------------------------------------------
  26. These are the steps for installing the Android SDK using command line. The
  27. advantage of this approach is the simplicity and small download/install size. It
  28. can be more challenging though. The Android Studio approach is easier, but it
  29. requires downloading and installing Android Studio (which may require more than
  30. 1 GB of storage).
  31. Install a JDK
  32. ^^^^^^^^^^^^^
  33. The Android SDK doesn't come with Java, so it needs to be installed manually.
  34. You need to install a Java SDK (**not** just the runtime or JRE).
  35. `OpenJDK 8 <https://adoptopenjdk.net/index.html>`__ is recommended.
  36. Oracle JDK 8 should also work. Later versions may not work for
  37. Android development.
  38. Download the command-line tools
  39. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  40. Go to the `Android Studio download page <https://developer.android.com/studio/#command-tools>`_.
  41. To save disk space, you don't want the full IDE, so don't download it.
  42. .. note::
  43. If you do want Android Studio, read further down for instructions for
  44. doing the same using Android Studio.
  45. Look on that page for the *Command line tools only* section. Currently, they are listed under
  46. *Download Options*. Scroll down a bit until you see them.
  47. .. image:: img/custom_build_command_line.png
  48. Download the ZIP file for your platform, there will be a single ``tools``
  49. folder inside:
  50. .. image:: img/custom_build_zip.png
  51. This may appear a little confusing, but be sure to follow these instructions
  52. carefully:
  53. Create a new folder anywhere you want named ``android-sdk`` (it **must** be
  54. an empty directory). On Windows, the following path is usually good enough:
  55. .. code-block:: none
  56. C:\users\<yourusername>\Documents\android-sdk
  57. Unzip the Android SDK ZIP file you just downloaded there. The only thing in the
  58. directory you created in the previous step should be the ``tools`` folder with
  59. its contents inside, like this:
  60. .. code-block:: none
  61. android-sdk/
  62. android-sdk/tools/
  63. android-sdk/tools/allthefiles
  64. Accepting the licenses
  65. ^^^^^^^^^^^^^^^^^^^^^^
  66. To be able to use the Android SDK tools, Google requires you to accept
  67. its licenses.
  68. To do this, the ``sdkmanager`` must be executed from the command line with a
  69. special argument. Navigate to the ``tools/bin`` directory inside the SDK folder
  70. (instructions provided for Windows users, as Linux and macOS users are expected
  71. to understand how command line navigation works):
  72. .. image:: img/custom_build_bin_folder.png
  73. Then open a command line window:
  74. .. image:: img/custom_build_open_shell.png
  75. In there, run ``sdkmanager --licenses``:
  76. .. image:: img/custom_build_sdkmanager.png
  77. This will ask you to accept several licenses, just write ``y`` and press :kbd:`Enter`
  78. on every of them until it's done.
  79. Afterwards, install the platform tools (this is required to install ``adb``):
  80. .. image:: img/custom_build_platform_tools.png
  81. Generating the keystore
  82. ^^^^^^^^^^^^^^^^^^^^^^^
  83. Once the *platform tools* are installed, the last step is to generate a debug
  84. keystore (this is needed to build). Go up two folders by writing:
  85. .. code-block:: shell
  86. cd ..\..
  87. (or open a new shell in the ``android-sdk`` folder).
  88. And you need to input the following line (on Linux and macOS, this should work
  89. out of the box, for Windows there are further instructions below):
  90. .. code-block:: shell
  91. keytool -keyalg RSA -genkeypair -alias androiddebugkey -keypass android -keystore debug.keystore -storepass android -dname "CN=Android Debug,O=Android,C=US" -validity 9999
  92. On Windows, the full path to Java should be provided. You need to add ``&`` at
  93. the beginning of the line if you use PowerShell; it's not needed for the regular
  94. ``cmd.exe`` console.
  95. To make it clearer, here is an capture of a line that works on PowerShell (by
  96. adding ``&`` and the full Java path before ``keytool.exe``). Again, keep in mind that you
  97. need Java installed:
  98. .. image:: img/custom_build_command_line.png
  99. (right-click and open the image in a new tab if this appears too small)
  100. Setting up Godot
  101. ^^^^^^^^^^^^^^^^
  102. Go to the **Editor Settings** and set up a few fields in **Export > Android**.
  103. Make sure they look like the following:
  104. .. image:: img/custom_build_editor_settings.png
  105. (right-click and open the image in a new tab if this appears too small)
  106. As it can be seen, most paths are inside either the ``android-sdk`` folder you
  107. originally created, or inside the Java install. For Linux and macOS users,
  108. ``jarsigner`` is often located in ``/usr/bin``.
  109. With this, you should be all set.
  110. Install the Android SDK (Android Studio)
  111. ----------------------------------------
  112. If you just finished installing the SDK via the command-line tools, feel free to
  113. skip this section entirely. The Android Studio path is easier, but it takes up
  114. more disk space. It's also useful if you plan to develop Godot for Android
  115. (modify the Java source code) or if you plan to develop add-ons.
  116. Download and install Android Studio
  117. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  118. Download the latest version of Android Studio. When installing, pay attention to
  119. where the *android-sdk* directory is created.
  120. .. image:: img/custom_build_install_android_studio1.png
  121. .. note:: This is funny, the path it proposes by default contains whitespace (and complains about it). It must be changed.
  122. In any case, it's better to select a different path inside your user folders.
  123. The recommended one is usually:
  124. .. code-block:: none
  125. C:\Users\<yourusername>\Documents\android-sdk
  126. Replace *yourusername* by your actual user name. Once it's correct, select from
  127. the list above in the same screen:
  128. * Android SDK
  129. * Android SDK Platform
  130. The rest are not needed, because the build system will fetch them itself. After
  131. selecting them, go on with the installation.
  132. Generating the keystore
  133. ^^^^^^^^^^^^^^^^^^^^^^^
  134. Go to the folder where you installed ``android-sdk`` in the previous step, use File
  135. Explorer and open a command line tool there:
  136. .. image:: img/custom_build_open_shell.png
  137. The actual command line to type is the following. On Linux and macOS, it should
  138. work out of the box, but on Windows, it needs additional details (keep reading
  139. afterwards).
  140. .. code-block:: shell
  141. keytool -keyalg RSA -genkeypair -alias androiddebugkey -keypass android -keystore debug.keystore -storepass android -dname "CN=Android Debug,O=Android,C=US" -validity 9999
  142. On Windows, the full path to Java should be provided (and ``&`` needs to be
  143. added at the beginning on the line if you use PowerShell, it's not needed for
  144. the regular ``cmd.exe`` console). Don't worry, at least by using Android Studio
  145. on Windows, Java comes bundled with it.
  146. To make it clearer, here is a screen capture of a line that works on PowerShell
  147. (by adding ``&`` and the full Java Path to ``keytool.exe``; remove ``&`` if you
  148. use ``cmd.exe``). It uses a path to the Java version that comes with Android
  149. Studio:
  150. .. image:: img/custom_build_command_line2.png
  151. (right-click and open the image in a new tab if this appears too small)
  152. Setting up Godot
  153. ^^^^^^^^^^^^^^^^
  154. Go to the **Editor Settings** and set up a few fields in **Export > Android**.
  155. Make sure they look like the following:
  156. .. image:: img/custom_build_editor_settings2.png
  157. (right-click and open the image in a new tab if this appears too small)
  158. As it can be seen, most paths are inside either the ``android-sdk`` folder you
  159. originally created, or inside the Java install. For Linux and macOS users,
  160. ``jarsigner`` is often located in ``/usr/bin``.
  161. With this, you should be all set.
  162. Enabling the custom build and exporting
  163. ---------------------------------------
  164. When setting up the Android project in the **Project > Export** dialog,
  165. **Custom Build** needs to be enabled:
  166. .. image:: img/custom_build_enable.png
  167. From now on, attempting to export the project or one-click deploy will call the
  168. `Gradle <https://gradle.org/>`__ build system to generate fresh templates (this
  169. window will appear every time):
  170. .. image:: img/custom_build_gradle.png
  171. The templates built will be used automatically afterwards, so no further
  172. configuration is needed.