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.5 以降

  • 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 11 (either OpenJDK or Oracle JDK).

    • ビルドされたものが ojdkbuild にてダウンロードできます。

参考

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

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

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

  • Set the environment variable ANDROID_SDK_ROOT 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:

    tools/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.

    tools/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_SDK_ROOT=/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=release android_arch=armv7
scons platform=android target=release android_arch=arm64v8
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=release_debug android_arch=armv7
scons platform=android target=release_debug android_arch=arm64v8
cd platform/android/java
# On Windows
.\gradlew generateGodotTemplates
# On Linux and macOS
./gradlew generateGodotTemplates

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

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 android_arch=x86, and android_arch=x86_64 arguments before building the APK with Gradle. For example, for the release template:

scons platform=android target=release android_arch=armv7
scons platform=android target=release android_arch=arm64v8
scons platform=android target=release android_arch=x86
scons platform=android target=release android_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 cleanGodotTemplates
# On Linux and macOS
./gradlew cleanGodotTemplates

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

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

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

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

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

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

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

  • macOS: $HOME/Library/Application Support/Godot/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\ ディレクトリで結果のファイルを参照するだけで、次回ビルド時にカスタム テンプレートが自動的に参照されます。

トラブルシューティング

Platform doesn't appear in SCons

Double-check that you've set the ANDROID_SDK_ROOT 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.solibs/<android_arch>/ にありません。ここで <android_arch> はデバイスのアーキテクチャです。

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

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