Up to date

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

Android用のコンパイル

参考

This page describes how to compile Android export template binaries from source. If you're looking to export your project to Android instead, read Android用にエクスポート.

注意

たいていの場合、デプロイヤーとエクスポートテンプレートはビルトインのもので十分です。Android APKを手動でコンパイルするのは、デプロイヤーのためにカスタムビルドやカスタムパッケージを用意する場合がほとんどです。

また、カスタムのエクスポート テンプレートを作成するときでも、チュートリアルAndroid用にエクスポートのステップを追う必要があります。

必要条件

Windows、Linux、またはmacOSでコンパイルするには、次のことが必要です:

  • Python 3.6+.

  • 3.0以降のSCons ビルドシステム。

  • Android SDK (コマンドライン ツールで十分です)。

    • Required SDK components will be automatically installed.

    • On Linux,

      do not use an Android SDK provided by your distribution's repositories as it will often be outdated.

  • Gradle(欠落している場合は自動的にダウンロードされ、インストールされます)。

  • JDK 17 (either OpenJDK or Oracle JDK).

参考

To get the Godot source code for compiling, see ソースの取得.

Godotにおける基本的なSconsの使い方については、ビルドシステムの説明を参照してください。

ビルドシステムのセットアップ

  • Set the environment variable ANDROID_HOME to point to the Android SDK. If you downloaded the Android command-line tools, this would be the folder where you extracted the contents of the ZIP archive.

  • Install the necessary SDK components in this folder:

    • Accept the SDK component licenses by running the following command where android_sdk_path is the path to the Android SDK, then answering all the prompts with y:

    cmdline-tools/latest/bin/sdkmanager --sdk_root=<android_sdk_path> --licenses
    
    • Complete setup by running the following command where android_sdk_path is the path to the Android SDK.

    cmdline-tools/latest/bin/sdkmanager --sdk_root=<android_sdk_path> "platform-tools" "build-tools;30.0.3" "platforms;android-29" "cmdline-tools;latest" "cmake;3.10.2.4988404"
    

参考

To set the environment variable on Windows, press Windows + R, type "control system", then click on Advanced system settings in the left pane, then click on Environment variables on the window that appears.

参考

To set the environment variable on Linux or macOS, use export ANDROID_HOME=/path/to/android-sdk where /path/to/android-sdk points to the root of the SDK directories.

エクスポートテンプレートのビルド

Godotには、Android用の2つのエクスポートテンプレートが必要です。最適化された "release" テンプレート(android_release.apk)とデバッグテンプレート (android_debug.apk)です。 Googleは2019年8月からすべてのAPKにARMv8(64ビット)ライブラリを含めることを要求するため、以下のコマンドはARMv7およびARMv8ライブラリの両方を含むAPKを構築します。

Compiling the standard export templates is done by calling SCons from the Godot root directory with the following arguments:

  • リリーステンプレート(Debugging Enabled をオフにしてエクスポートするときに使用)

scons platform=android target=template_release arch=arm32
scons platform=android target=template_release arch=arm64
cd platform/android/java
# On Windows
.\gradlew generateGodotTemplates
# On Linux and macOS
./gradlew generateGodotTemplates

得られたAPKは bin/android_release.apk にあります。

  • デバッグテンプレート(Debugging Enabled をオンにしてエクスポートするときに使用)

scons platform=android target=template_debug arch=arm32
scons platform=android target=template_debug arch=arm64
cd platform/android/java
# On Windows
.\gradlew generateGodotTemplates
# On Linux and macOS
./gradlew generateGodotTemplates

得られたAPKは bin/android_debug.apk にあります。

参考

If you want to enable Vulkan validation layers, see Vulkan validation layers on Android.

x86デバイスのサポートの追加

If you also want to include support for x86 and x86-64 devices, run the SCons command a third and fourth time with the arch=x86_32, and arch=x86_64 arguments before building the APK with Gradle. For example, for the release template:

scons platform=android target=template_release arch=arm32
scons platform=android target=template_release arch=arm64
scons platform=android target=template_release arch=x86_32
scons platform=android target=template_release arch=x86_64
cd platform/android/java
# On Windows
.\gradlew generateGodotTemplates
# On Linux and macOS
./gradlew generateGodotTemplates

これにより、すべてのプラットフォームで機能するファットバイナリが作成されます。エクスポートされたプロジェクトの最終的なAPKサイズは、エクスポート時にサポートすることを選択したプラットフォームによって異なります。つまり、未使用のプラットフォームはAPKから削除されます。

エクスポートテンプレートのクリーニング

次のコマンドを使用して、生成されたエクスポートテンプレートを削除できます:

cd platform/android/java
# On Windows
.\gradlew clean
# On Linux and macOS
./gradlew clean

エクスポートテンプレートの使用

Godotには、エディタと同じバージョン/コミットに対してコンパイルされたAPKのリリースとデバッグが必要です。エディタに公式のバイナリを使用している場合は、必ず一致するエクスポートテンプレートをインストールするか、同じバージョンから独自のテンプレートをビルドしてください。

ゲームをエクスポートするとき、GodotはAPKを開き、内部のいくつかを変更してファイルを追加します。

テンプレートのインストール

新しくコンパイルされたテンプレート(android_debug.apk および android_release.apk) は、それぞれの名前でGodotのテンプレートフォルダにコピーする必要があります。テンプレートフォルダは次の場所にあります:

  • Windows: %APPDATA%\Godot\export_templates\<version>\

  • Linux: $HOME/.local/share/godot/export_templates/<version>/

  • macOS: $HOME/Library/Application Support/Godot/export_templates/<version>/

<version> `` の形式は ``major.minor[.patch].status で、Godotソースリポジトリの version.py の値を使用します(例: 3.0.5.stable または 3.1.dev)。また、エクスポートテンプレートの隣にある version.txt ファイルにこの同じバージョン文字列を書き込む必要があります。

ただし、カスタムモジュールまたはカスタムC++コードを記述している場合は、代わりにここでカスタムエクスポートテンプレートとしてAPKを構成することをお勧めします:

../../../_images/andtemplates.png

コピーする必要もなく、Godotソースフォルダの bin\ ディレクトリで結果のファイルを参照するだけで、次回ビルド時にカスタム テンプレートが自動的に参照されます。

Building the Godot editor

Compiling the editor is done by calling SCons from the Godot root directory with the following arguments:

scons platform=android arch=arm32 production=yes target=editor
scons platform=android arch=arm64 production=yes target=editor
scons platform=android arch=x86_32 production=yes target=editor
scons platform=android arch=x86_64 production=yes target=editor
cd platform/android/java
# On Windows
.\gradlew generateGodotEditor
# On Linux and macOS
./gradlew generateGodotEditor

The resulting APK will be located at bin/android_editor_builds/android_editor-release.apk.

Removing the Editor templates

You can use the following commands to remove the generated editor templates:

 cd platform/android/java
 # On Windows
.\gradlew clean
# On Linux and macOS
./gradlew clean

Installing the Godot editor

With an Android device with Developer Options enabled, connect the Android device to your computer via its charging cable to a USB/USB-C port. Open up a Terminal/Command Prompt and run the following commands from the root directory with the following arguments:

adb install ./bin/android_editor_builds/android_editor-release.apk

トラブルシューティング

Platform doesn't appear in SCons

Double-check that you've set the ANDROID_HOME environment variable. This is required for the platform to appear in SCons' list of detected platforms. See Setting up the buildsystem for more information.

アプリケーションがインストールされていません

Androidは、アプリケーションが正しくインストールされていないことを訴えます。その場合:

  • デバッグ キーストアが正しく生成されていることを確認します。

  • jarsigner実行可能ファイルがJDK 8からのものであることを確認します。

それでも失敗する場合は、コマンドラインを開き、`logcat <https://developer.android.com/studio/command-line/logcat>`_を実行します。

adb logcat

次に、アプリケーションのインストール中に出力を確認します。エラーメッセージが表示されます。理解できない場合は支援を求めてください。

アプリケーションは直ちに終了します

アプリケーションは実行されてもすぐに終了する場合は、次のいずれかの理由が考えられます:

  • エディタのバージョンと一致するエクスポートテンプレートを使用してください。 新しいGodotバージョンを使用する場合は、テンプレートも更新する必要があります

  • libgodot_android.so is not in libs/<arch>/ where <arch> is the device's architecture.

  • デバイスのアーキテクチャが、エクスポートされたものと一致しません。テンプレートがそのデバイスのアーキテクチャ用に構築されていること、およびエクスポート設定にそのアーキテクチャのサポートが含まれていることを確認してください。

いずれの場合も、adb logcat にはエラーの原因も表示されます。