Android用のコンパイル

注意

In most cases, using the built-in deployer and export templates is good enough. Compiling the Android APK manually is mostly useful for custom builds or custom packages for the deployer.

Also, you still need to follow the steps mentioned in the Androidへのエクスポート tutorial before attempting to build a custom export template.

必要条件

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

  • Python 2.7+ or Python 3.5+
  • SCons build system
  • Android SDK (command-line tools are sufficient)
    • Required SDK components will be automatically installed by Gradle (except the NDK)
  • Android NDK r17 or later
  • Gradle(欠落している場合は自動的にダウンロードされ、インストールされます)
  • JDK 8 (either OpenJDK or Oracle JDK)
    • JDK 9 or later are not currently supported
    • You can download a build from ojdkbuild

参考

For a general overview of SCons usage for Godot, see ビルドシステムの説明.

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

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. Later on, gradlew will install necessary SDK components in this folder. However, you need to accept the SDK component licenses before they can be downloaded by Gradle. This can be done by running the following command from the root of the SDK directory, then answering all the prompts with y:

tools/bin/sdkmanager --licenses

Set the environment variable ANDROID_NDK_ROOT to point to the Android NDK. You also might need to set the variable ANDROID_NDK_HOME to the same path, especially if you are using custom Android modules, since some Gradle plugins rely on the NDK and use this variable to determine its location.

To set those environment variables 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 those environment variables on Linux or macOS, use export ANDROID_HOME=/path/to/android-sdk and export ANDROID_NDK_ROOT=/path/to/android-ndk where /path/to/android-sdk and /path/to/android-ndk point to the root of the SDK and NDK directories.

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

Godot needs two export templates for Android: the optimized "release" template (android_release.apk) and the debug template (android_debug.apk). As Google will require all APKs to include ARMv8 (64-bit) libraries starting from August 2019, the commands below will build an APK containing both ARMv7 and ARMv8 libraries.

Compiling the standard export templates is done by calling SCons with the following arguments:

  • Release template (used when exporting with Debugging Enabled unchecked)
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

The resulting APK will be located at bin/android_release.apk.

  • Debug template (used when exporting with Debugging Enabled checked)
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

The resulting APK will be located at bin/android_debug.apk.

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

If you also want to include support for x86 devices, run the SCons command a third time with the android_arch=x86 argument 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
cd platform/android/java
# On Windows
.\gradlew generateGodotTemplates
# On Linux and macOS
./gradlew generateGodotTemplates

This will create a fat binary that works on all platforms. The final APK size of exported projects will depend on the platforms you choose to support when exporting; in other words, unused platforms will be removed from the APK.

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

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

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

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

Godot needs release and debug APKs that were compiled against the same version/commit as the editor. If you are using official binaries for the editor, make sure to install the matching export templates, or build your own from the same version.

When exporting your game, Godot opens the APK, changes a few things inside and adds your files.

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

The newly-compiled templates (android_debug.apk and android_release.apk) must be copied to Godot's templates folder with their respective names. The templates folder can be located in:

  • Windows: %APPDATA%\Godot\templates\<version>\
  • Linux: $HOME/.local/share/godot/templates/<version>/
  • macOS: $HOME/Library/Application Support/Godot/templates/<version>/

<version> is of the form major.minor[.patch].status using values from version.py in your Godot source repository (e.g. 3.0.5.stable or 3.1.dev). You also need to write this same version string to a version.txt file located next to your export templates.

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

../../_images/andtemplates.png

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

トラブルシューティング

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

Android might complain the application is not correctly installed. If so:

  • デバッグ キーストアが正しく生成されていることを確認します。
  • Check that the jarsigner executable is from JDK 8.

If it still fails, open a command line and run logcat:

adb logcat

Then check the output while the application is installed; the error message should be presented there. Seek assistance if you can't figure it out.

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

If the application runs but exits immediately, this might be due to one of the following reasons:

  • エディタのバージョンと一致するエクスポートテンプレートを使用してください。 新しいGodotバージョンを使用する場合は、テンプレートも更新する必要があります
  • libgodot_android.so is not in libs/<android_arch>/ where <android_arch> is the device's architecture.
  • The device's architecture does not match the exported one(s). Make sure your templates were built for that device's architecture, and that the export settings included support for that architecture.

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