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.
Checking the stable version of the documentation...
Android Studio
Android Studio 是由 Google 與 JetBrains 提供的免費 Android 開發 IDE,基於 IntelliJ IDEA,內建功能豐富的編輯器,支援 Java 與 C/C++。可用於 Godot 核心引擎與 Android 平台相關原始碼的開發。
匯入專案
在 Android Studio 的歡迎畫面中選擇 Open。
Android Studio 的歡迎畫面。
前往
<Godot 根目錄>/platform/android/java並選擇settings.gradle檔案。Android Studio 會匯入並建立專案索引。
Android Studio 專案結構
Godot Android 專案是以 Android Studio 的模組方式 組織的:
lib 模組:
它位於
<Godot root directory>/platform/android/java/lib路徑下,是一個 庫模組(library module) 。它的作用是將 Godot 的 Java 程式碼和原生(native)程式碼整合在一起,並將其打包成一個可復用的 Android library。生成的 Godot Android library 連同其 its documentation ,已通過 MavenCentral 提供給其他的 Android 模組/專案使用。
editor 模組:
位於
<Godot root directory>/platform/android/java/editor中,這是一個 應用程式模組,用於存放 Godot 編輯器的 Android and XR ports 的原始碼。這個模組取決於 lib 模組。
app 模組:
該資料夾位於
<Godot root directory>/platform/android/java/app下,它是一個應用模組(application module),用於存放安卓建置範本的原始碼。這個模組取決於 lib 模組。
建置與除錯 editor 模組
要建置
editor模組:
備註
Build with the terminal using the following command:
cd platform/android/java
./gradlew :editor:assembleAndroidDebug
要除錯
editor模組:在上方選單選擇 View > Tool Windows > Build Variants 開啟 Build Variants 視窗。
在 Build Variants(建置變體) 視窗中,請確保 Active Build Variant(目前啟用的建置變體) 這一列下,
:editor這一項被設定為了某個 Debug(除錯) 版本的變體。
於上方選單點選 Run > Edit Configurations... 開啟 運作/除錯設定 視窗。
於 運作/除錯設定 視窗中,選擇
editor條目,並於 Debugger 區塊將 Debug Type 設為Dual (Java + Native)在 Symbol Directories(符號目錄) 部分,點擊
+號,然後新增platform/android/java/lib/libs/tools/debug目錄。
從上方選單選擇 Run > Debug 'editor' 或點擊 偵錯圖示。
建置與除錯 app 模組
The app module is an empty shell which is filled by the Godot Editor during the export process.
As such for development, the app module requires the presence of a manually exported Godot project to run.
Follow these steps to configure and manually export a Godot project to use with the app module:
Within the Godot Editor export window, create a new Android export preset.
Enable Gradle Build > Use Gradle Build in the Android export preset.
Set the Gradle Build > Export Format to Export AAR.
Set the Export Path for the generated
AARto<Godot root directory>/platform/android/java/app/libs/exportedProjectAAR/.Make sure Package > Show in App Library is enabled.
Configure any other export options that makes sense for the project.
Click on , and export the project to the specified
Export Path.
Now that's done, you can follow the instructions below to run/debug the app module:
要建置
app模組:
備註
Build with the terminal using the following command:
cd platform/android/java
./gradlew :app:assembleStandardDebug
要除錯
app模組:在上方選單選擇 View > Tool Windows > Build Variants 開啟 Build Variants 視窗。
在 Build Variants(建置變體) 視窗中,請確保在 Active Build Variant(目前啟用的建置變體) 這一列下,
:app這一項被設定為了某個 Debug(除錯) 版本的變體。
於上方選單點選 Run > Edit Configurations... 開啟 運作/除錯設定 視窗。
於 運作/除錯設定 視窗中,選擇
app條目,並於 Debugger 區塊將 Debug Type 設為Dual (Java + Native)在 Symbol Directories(符號目錄) 部分,點擊
+號,然後新增platform/android/java/lib/libs/debug目錄。
從上方選單選擇 Run > Debug 'app' 或點擊 偵錯圖示。
若遇到任何問題,請至 Godot Android 開發頻道 詢問協助。