Up to date

This page is up to date for Godot 4.2. If you still find outdated information, please open an issue.

Gradle builds for Android

Godot provides the option to build using the gradle buildsystem. Instead of using the already pre-built template that ships with Godot, an Android Java project gets installed into your project folder. Godot will then build it and use it as an export template every time you export the project.

有幾個原因會需要這麼做:

  • 要在建置前修改專案。

  • 建置專案時要加上外部 SDK。

Configuring the gradle build is a fairly straightforward process. But first you need to follow the steps in exporting for android up to Setting it up in Godot. After doing that, follow the steps below.

Set up the gradle build environment

Go to the Project menu, and install the Gradle Build template:

../../_images/gradle_build_install_template.webp

請確定有下載匯出樣板。若沒下載的話,該選單會協助下載。

A Gradle-based Android project will be created under res://android/build. Editing these files is not needed unless you really need to modify the project.

Enabling the gradle build and exporting

When setting up the Android project in the Project > Export dialog, Gradle Build needs to be enabled:

../../_images/gradle_build_enable.webp

接著,只要匯出專案或單鍵部署時,就會呼叫 ``Gradle <https://gradle.org/>`_ 建置系統,並產生新的樣板 (該視窗每次都會出現):

../../_images/gradle_build_gradle.webp

接著會自動使用樣板建置,不需要進一步設定。

備註

When using the gradle Android build system, assets that are placed within a folder whose name begins with an underscore will not be included in the generated APK. This does not apply to assets whose file name begins with an underscore.

例如,_example/image.png 將**不會**包含為素材,但``_image.png`` 會。