-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathbuild-android-apk.sh
executable file
·80 lines (65 loc) · 2.82 KB
/
build-android-apk.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/bin/bash
set -euo pipefail
# Set the explorer path to the current working directory.
EXPLORER_PATH="$(pwd)"
# Clone the Godot Android template if it does not exist.
if [ ! -d "${EXPLORER_PATH}/godot/android/" ]; then
echo "Checking out Godot Android template..."
git clone https://github.com/decentraland/godot-explorer-android-template "${EXPLORER_PATH}/godot/android"
fi
# Set JAVA_HOME if not already set.
if [ -z "${JAVA_HOME:-}" ]; then
export JAVA_HOME="/usr/lib/jvm/java-17-openjdk-amd64"
fi
echo "Build for Linux x86_64"
cd "${EXPLORER_PATH}"
cargo run -- install --platforms android
cargo run -- build
echo "Link export templates"
mkdir -p "${HOME}/.local/share/godot/export_templates/"
cd "${HOME}/.local/share/godot/export_templates/"
ln -sf "${EXPLORER_PATH}/.bin/godot/templates/templates/" "4.3.stable"
echo "Build for Android (arm64)"
cd "${EXPLORER_PATH}/lib"
bash android-build.sh
echo "Build for Android (x86_64)"
cd "${EXPLORER_PATH}/lib"
bash android-build.sh x86_64
# Temporarily disable strict error checking for the debug key setup.
set +e
echo "Setup Android Debug Keys"
cd /opt/ || exit 1
keytool -keyalg RSA -genkeypair -alias androiddebugkey \
-keypass android -keystore debug.keystore -storepass android \
-dname "CN=Android Debug,O=Android,C=US" -validity 9999 -deststoretype pkcs12
export GODOT_ANDROID_KEYSTORE_DEBUG_PATH="/opt/debug.keystore"
export GODOT_ANDROID_KEYSTORE_DEBUG_USER="androiddebugkey"
export GODOT_ANDROID_KEYSTORE_DEBUG_PASSWORD="android"
# Re-enable strict error checking.
set -e
cd "${EXPLORER_PATH}/godot/"
echo "Export Godot android.apk"
# Define the export command.
COMMAND="${EXPLORER_PATH}/.bin/godot/godot4_bin -e --headless --export-debug android ${EXPLORER_PATH}/android.apk"
if ! eval "$COMMAND"; then
echo "First attempt failed, retrying in 5 seconds..."
sleep 5
if ! eval "$COMMAND"; then
echo "Second attempt failed."
else
echo "Second attempt succeeded."
fi
else
echo "First attempt succeeded."
fi
# Preserve the original behavior with "|| true".
${EXPLORER_PATH}/.bin/godot/godot4_bin -e --headless --export-debug quest "${EXPLORER_PATH}/meta-quest.apk" || true
echo "Setting up to export godot .aab"
# Update export presets.
sed -i 's/gradle_build\/export_format=0/gradle_build\/export_format=1/' "${EXPLORER_PATH}/godot/export_presets.cfg"
sed -i 's/architectures\/x86_64=true/architectures\/x86_64=false/' "${EXPLORER_PATH}/godot/export_presets.cfg"
sed -i 's/package\/signed=true/package\/signed=false/' "${EXPLORER_PATH}/godot/export_presets.cfg"
echo "Export Godot AAB"
${EXPLORER_PATH}/.bin/godot/godot4_bin -e --headless --export-release android "${EXPLORER_PATH}/android-unsigned.aab" || true
${EXPLORER_PATH}/.bin/godot/godot4_bin -e --headless --export-release quest "${EXPLORER_PATH}/meta-quest-unsigned.aab" || true
echo "Finished."