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...
Compilation pour Android
Voir aussi
Cette page décrit comment compiler les binaires du modèle d'exportation Android à partir du code source. Si vous souhaitez plutôt exporter votre projet vers Android, lisez Exportation pour Android.
Note
Dans la plupart des cas, l'utilisation des modèles de déploiement et d'exportation intégrés est suffisante. La compilation manuelle de l'APK Android est surtout utile pour les constructions personnalisées ou les paquets personnalisés pour le déployeur.
Vous devez également suivre les étapes mentionnées dans le tutoriel Exportation pour Android avant de tenter de créer un modèle d'exportation personnalisé.
Pré-requis
Pour la compilation sous Windows, Linux ou macOS, les éléments suivants sont nécessaires :
SCons 4.0+ build system.
SDK Android (les outils en ligne de commande sont suffisants).
Les composants SDK requis seront automatiquement installés.
On Linux, do not use an Android SDK provided by your distribution's repositories as it will often be outdated.
On macOS, do not use an Android SDK provided by Homebrew as it will not be installed in a unified location.
Gradle (sera téléchargé et installé automatiquement s'il manque).
JDK 17 (either OpenJDK or Oracle JDK).
Vous pouvez télécharger un build à partir de Adoptium.
Voir aussi
Pour récupérer le code source de Godot pour le compiler, voir Obtenir la source.
Pour un aperçu général de l'utilisation de SCons pour Godot, voir Introduction au buildsystem.
Mise en place du système de construction(build)
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.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.
Linux or macOS: Add the text
export ANDROID_HOME="/path/to/android-sdk"
to your.bashrc
or.zshrc
where/path/to/android-sdk
points to the root of the SDK directories.
Installez les composants SDK nécessaires dans ce dossier :
Acceptez les licences des composants SDK en exécutant la commande suivante où
android_sdk_path
est le chemin vers le SDK Android, puis répondez à toutes les questions pary
:
cmdline-tools/latest/bin/sdkmanager --sdk_root=<android_sdk_path> --licenses
Terminez l'installation en exécutant la commande suivante où
android_sdk_path
est le chemin vers le SDK Android.
cmdline-tools/latest/bin/sdkmanager --sdk_root=<android_sdk_path> "platform-tools" "build-tools;34.0.0" "platforms;android-34" "cmdline-tools;latest" "cmake;3.10.2.4988404" "ndk;23.2.8568313"
After setting up the SDK and environment variables, be sure to restart your terminal to apply the changes. If you are using an IDE with an integrated terminal, you need to restart the IDE.
Run
scons platform=android
. If this fails, go back and check the steps. If you completed the setup correctly, the NDK will begin downloading. If you are trying to compile GDExtension, you need to first compile the engine to download the NDK, then you can compile GDExtension.
Construction(Building) des modèles d'exportation
Godot needs three export templates for Android: the optimized "release"
template (android_release.apk
), the debug template (android_debug.apk
),
and the Gradle build template (android_source.zip
).
As Google requires all APKs to include ARMv8 (64-bit) libraries since August 2019,
the commands below build templates containing both ARMv7 and ARMv8 libraries.
La compilation des modèles d'exportation standard se fait en appelant SCons depuis le répertoire racine de Godot avec les arguments suivants :
Modèle de release (utilisé lors de l'exportation avec Debugging Enabled non coché)
scons platform=android target=template_release arch=arm32
scons platform=android target=template_release arch=arm64 generate_apk=yes
Modèle de débogage (utilisé lors de l'exportation avec Débogage activé coché)
scons platform=android target=template_debug arch=arm32
scons platform=android target=template_debug arch=arm64 generate_apk=yes
(Optional) Dev template (used when troubleshooting)
scons platform=android target=template_debug arch=arm32 dev_build=yes
scons platform=android target=template_debug arch=arm64 dev_build=yes generate_apk=yes
The resulting templates will be located under the bin
directory:
bin/android_release.apk
for the release templatebin/android_debug.apk
for the debug templatebin/android_dev.apk
for the dev templatebin/android_source.zip
for the Gradle build template
Note
If you are changing the list of architectures you're building, remember to add
generate_apk=yes
to the last architecture you're building, so that the template files are generated after the build.To include debug symbols in the generated templates, add the
debug_symbols=yes
parameter to the SCons command.
Voir aussi
If you want to enable Vulkan validation layers, see Vulkan validation layers on Android.
Ajout de la prise en charge des appareils 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 generate_apk=yes
This will create template binaries that works on all platforms. The final binary 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 binary.
Nettoyage des modèles d'exportation générés
Vous pouvez utiliser les commandes suivantes pour supprimer les modèles d'exportation générés :
cd platform/android/java
# On Windows
.\gradlew clean
# On Linux and macOS
./gradlew clean
Utilisation des modèles d'exportation
Godot needs release and debug binaries 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 uses the templates as a base, and updates their content as needed.
Installation des modèles
The newly-compiled templates (android_debug.apk
, android_release.apk
, and android_source.zip
) must be copied to Godot's templates folder
with their respective names. The templates folder can be located in:
Windows:
%APPDATA%\Godot\export_templates\<version>\
Linux:
$HOME/.local/share/godot/export_templates/<version>/
macOS:
$HOME/Library/Application Support/Godot/export_templates/<version>/
<version>
is of the form major.minor[.patch].status
using values from
version.py
in your Godot source repository (e.g. 4.1.3.stable
or 4.2.dev
).
You also need to write this same version string to a version.txt
file located
next to your export templates.
However, if you are writing your custom modules or custom C++ code, you might instead want to configure your template binaries as custom export templates here:

Vous n'avez même pas besoin de les copier, vous pouvez simplement référencer le fichier résultant dans le répertoire bin\
de votre dossier source Godot, de sorte que la prochaine fois que vous construirez, vous aurez automatiquement les modèles personnalisés référencés.
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 generate_apk=yes
You can add the
dev_build=yes
parameter to generate a dev build of the Godot editor.You can add the
debug_symbols=yes
parameter to include the debug symbols in the generated build.You can skip certain architectures depending on your target device to speed up compilation.
Remember to add generate_apk=yes
to the last architecture you're building, so that binaries are generated after the build.
The resulting binaries will be located under bin/android_editor_builds/
.
Removing the Editor binaries
You can use the following commands to remove the generated editor binaries:
cd platform/android/java
# On Windows
.\gradlew clean
# On Linux and macOS
./gradlew clean
Installing the Godot editor APK
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
Dépannage
La plate-forme n'apparaît pas dans 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.
Application non installée
Android pourrait se plaindre que l'application n'est pas correctement installée. Si c'est le cas :
Vérifiez que la keystore de débogage est correctement générée.
Vérifiez que l'exécutable jarsigner provient du JDK 8.
S'il échoue encore, ouvrez une ligne de commande et lancez logcat :
adb logcat
Vérifiez alors la sortie pendant que l'application est installée ; le message d'erreur devrait être présenté là. Demander assistance si vous n'arrivez pas à vous en sortir.
L'application se ferme immédiatement
Si l'application s'exécute mais se ferme immédiatement, cela peut être due à l'une des raisons suivantes :
Assurez-vous d'utiliser des modèles d'exportation correspondant à la version de votre éditeur ; si vous utilisez une nouvelle version de Godot, vous devez mettre à jour tous les modèles.
libgodot_android.so
is not inlibs/<arch>/
where<arch>
is the device's architecture.L'architecture de l'appareil ne correspond pas à celle exportée. Assurez-vous que vos modèles ont été créés pour l'architecture de cet appareil et que les paramètres d'exportation incluent la prise en charge de cette architecture.
Dans tous les cas, adb logcat
devrait également indiquer la cause de l'erreur.