Attention: Here be dragons

This is the latest (unstable) version of this documentation, which may document features not available in or compatible with released stable versions of Godot.

Android Studio

Android Studio 是由 GoogleJetBrains 提供的免費 Android 開發 IDE,基於 IntelliJ IDEA,內建功能豐富的編輯器,支援 Java 與 C/C++。可用於 Godot 核心引擎與 Android 平台相關原始碼的開發。

匯入專案

  • 在 Android Studio 的歡迎畫面中選擇 Open

../../../_images/android_studio_setup_project_1.png

Android Studio 的歡迎畫面。

  • 前往 <Godot 根目錄>/platform/android/java 並選擇 settings.gradle 檔案。

  • Android Studio 會匯入並建立專案索引。

Android Studio 專案結構

Godot Android 專案是以 Android Studio 的模組方式 組織的:

  • lib module:

    • Located under <Godot root directory>/platform/android/java/lib, this is a library module that organizes the Godot java and native code and make it available as a reusable Android library.

    • The generated Godot Android library is made available for other Android modules / projects via MavenCentral, along with its documentation.

  • editor module:

    • Located under <Godot root directory>/platform/android/java/editor, this is an application module that holds the source code for the Android and XR ports of the Godot Editor.

    • This module has a dependency on the lib module.

  • app module:

    • Located under <Godot root directory>/platform/android/java/app, this is an application module that holds the source code for the Android build templates.

    • This module has a dependency on the lib module.

建置與除錯 editor 模組

  • 要建置 editor 模組:

    ../../../_images/android_studio_editor_configurations_drop_down.webp
    • 從上方選單選擇 Run > Run 'editor' 或點擊 執行圖示

  • 要除錯 editor 模組:

    • 在上方選單選擇 View > Tool Windows > Build Variants 開啟 Build Variants 視窗。

    • In the Build Variants window, make sure that in the Active Build Variant column, the :editor entry is set to one of the Debug variants.

    ../../../_images/android_studio_editor_build_variant.webp
    • 於上方選單點選 Run > Edit Configurations... 開啟 運作/除錯設定 視窗。

    • 運作/除錯設定 視窗中,選擇 editor 條目,並於 Debugger 區塊將 Debug Type 設為 Dual (Java + Native)

    • Click the + sign under the Symbol Directories section, and add the platform/android/java/lib/libs/tools/debug directory.

    ../../../_images/android_studio_editor_debug_type_setup.webp
    • 從上方選單選擇 Run > Debug 'editor' 或點擊 偵錯圖示

建置與除錯 app 模組

The app module requires the presence of a Godot project in its assets directory (<Godot root directory>/platform/android/java/app/src/main/assets) to run. This is usually handled by the Godot Editor during the export process. While developing in Android Studio, it's necessary to manually add a Godot project under that directory to replicate the export process. Once that's done, you can follow the instructions below to run/debug the app module:

  • 要建置 app 模組:

    ../../../_images/android_studio_app_configurations_drop_down.webp
    • 從上方選單選擇 Run > Run 'app' 或點擊 執行圖示

  • 要除錯 app 模組:

    • 在上方選單選擇 View > Tool Windows > Build Variants 開啟 Build Variants 視窗。

    • In the Build Variants window, make sure that in the Active Build Variant column, the :app entry is set to one of the Debug variants.

    ../../../_images/android_studio_app_build_variant.webp
    • 於上方選單點選 Run > Edit Configurations... 開啟 運作/除錯設定 視窗。

    • 運作/除錯設定 視窗中,選擇 app 條目,並於 Debugger 區塊將 Debug Type 設為 Dual (Java + Native)

    • Click the + sign under the Symbol Directories section, and add the platform/android/java/lib/libs/debug directory.

    ../../../_images/android_studio_app_debug_type_setup.webp
    • 從上方選單選擇 Run > Debug 'app' 或點擊 偵錯圖示

若遇到任何問題,請至 Godot Android 開發頻道 詢問協助。