In this post we are going to automate Godot Android build process on linux. When we export our game, the engine takes the template, modifies it and then spit it back the final game apk file. The official website provides basic export templates but they are the basic ones and integrating our game with third party libraries like Google Play Services or Admob require building custom export templates.
First of all, we need to download the Godot engine source from github. Inside the downloaded folder, there is a '/modules' folder where we put our required modules. When creating the export templates the engine will include the modules into the template.
The modules are inserted into the export templates and as a result, some of the project specific things like application ids will be bound to the template. So when managing multiple android projects, we need to make sure we use the correct templates. Compiling and switching back between multiple projects is a difficult process.
Thankfully, github user Hugo Locurcio created a nice shell script here https://gist.github.com/Calinou/3e9f6a961c7c9364a681f8f1a5375247 which helps us create export templates by simply running the script instead of typing all the commands. I modified it and now the script will manage the required project modules and compiles the export templates.
So let's jump into the process.
Step 1: Download Godot source from githubThe source is available from Godot official repository.
Step 2: Install dependencies for the compilationRefer here to prepare your computer for compiling export templates for android.
Step 3: Create the project directory structureOur project directory should look like this
- /project_main_dir -> our main directory for the game project
- /godot_project_dir -> godot project directory
- /templates
- /modules -> place our modules inside this
Place our required modules inside the /modules inside the /project_main_dir
Step 5: Configure the automation script and run itPlace the generate.sh script inside the Godot source.
#!/bin/sh -x #This script generates export templates for Godot android builds #Some of the codes from https://gist.github.com/Calinou/3e9f6a961c7c9364a681f8f1a5375247 export ANDROID_HOME="/path/to/android-sdk-linux" export ANDROID_NDK_ROOT="/path/to/android-ndk-r13" if [ -f "${1}" ] ; then echo "$1 is not a directory"; return fi GODOT_SOURCE_DIR=$(pwd) GODOT_MODULE_DIR="${GODOT_SOURCE_DIR}/modules" EXPORT_TEMPLATE_DIR=$1 PROJECT_MODULE_DIR=$1"/modules" mkdir -p $GODOT_MODULE_DIR find ${GODOT_MODULE_DIR} -mindepth 1 -maxdepth 1 -type d -name "*_temp" -exec rm -rf "{}" \; for i in `find ${PROJECT_MODULE_DIR} -mindepth 1 -maxdepth 1 -type d`; do NEWNAME="${i}_temp" cp -a $i $NEWNAME done find ${PROJECT_MODULE_DIR} -mindepth 1 -maxdepth 1 -name "*_temp" -type d -exec cp -a "{}" "${GODOT_MODULE_DIR}" \; find ${PROJECT_MODULE_DIR} -mindepth 1 -maxdepth 1 -type d -name "*_temp" -exec rm -rf "{}" \; # Build Godot for Android in debug and release mode scons p=android -j$(nproc) colored=yes tools=no target=release_debug scons p=android -j$(nproc) colored=yes tools=no target=release # Create APK using Gradle cd platform/android/java ./gradlew build # Copy to export templates directory cd ../../../bin/ cp android_debug.apk android_release.apk $EXPORT_TEMPLATE_DIR
Open the script in a text editor and change the android sdk and ndk path. Then run it in the terminal like this.
./generate.sh /path/to/templates
The export templates will be generated and copied to the /templates.
We need to set the export templates in the engine to use them.
Now let's talk about the script. It just copies all the modules to the Godot source /modules with "_temp" appended to their name. Then it compiles and the templates generated are moved to our templates directory.
How does this help managing multiple android projects?
All modules and their project specific data will reside inside our project directory. Our export templates will also be there. When compiling for another project, the previous modules from the source are removed and only the current ones are copied. And thus we don't need to manually copy, paste things between project and the source.
I found this workflow fast and easy, I hope this will help you all. Thanks for reading.
[Total: 0 Average: 0/5]