-
-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathbuild_android.sh
More file actions
executable file
·148 lines (132 loc) · 5.33 KB
/
Copy pathbuild_android.sh
File metadata and controls
executable file
·148 lines (132 loc) · 5.33 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/usr/bin/env bash
#
# Builds the CoinTex Android package, ready to upload to Google Play.
#
# What it does:
# 1. Activates the venv and makes sure buildozer and Cython are installed.
# 2. Checks that the Android build tools are present (installed by setup_venv.sh).
# 3. Creates a release upload key the first time, and exports its certificate.
# 4. Builds the signed release files in ./bin (an .aab for Google Play and an
# .apk you can install on a device for testing).
# 5. Prints the files and their package id, target SDK and architectures.
#
# Options:
# ./build_android.sh build the release .aab and .apk
# ./build_android.sh --debug build a quick unsigned debug .apk only
# ./build_android.sh --skip-deps do not check the system build tools
#
# The first build downloads the Android SDK and NDK (a few GB) and can take
# 30 to 60 minutes. It must run on Linux.
#
set -euo pipefail
cd "$(dirname "$(readlink -f "$0")")"
PROJECT_DIR="$(pwd)"
MODE="release"
SKIP_DEPS=0
for arg in "$@"; do
case "$arg" in
--debug) MODE="debug" ;;
--skip-deps) SKIP_DEPS=1 ;;
*) echo "Unknown option: $arg" >&2; exit 2 ;;
esac
done
VENV_DIR="venv"
KEYSTORE_FILE="$PROJECT_DIR/cointex-upload.keystore"
KEYSTORE_ALIAS="cointex-upload"
ENV_FILE="$PROJECT_DIR/.env"
# Make sure the venv and buildozer are ready.
if [[ ! -d "$VENV_DIR" ]]; then
echo "venv missing, creating it with setup_venv.sh"
./setup_venv.sh
fi
# shellcheck disable=SC1091
source "$VENV_DIR/bin/activate"
python -m pip install --upgrade buildozer cython
# Check the Android build tools. setup_venv.sh installs them.
if [[ "$SKIP_DEPS" -eq 0 ]]; then
missing=""
command -v javac >/dev/null 2>&1 || missing="$missing openjdk-17-jdk"
command -v autoconf >/dev/null 2>&1 || missing="$missing autoconf"
command -v automake >/dev/null 2>&1 || missing="$missing automake"
command -v libtoolize >/dev/null 2>&1 || missing="$missing libtool"
command -v cmake >/dev/null 2>&1 || missing="$missing cmake"
if [[ -n "$missing" ]]; then
echo "Android build tools are missing:$missing" >&2
echo "Run ./setup_venv.sh first, then run this script again." >&2
exit 1
fi
fi
# A quick debug build needs no signing.
if [[ "$MODE" == "debug" ]]; then
echo "Building a debug apk"
buildozer android debug
echo "Done. Files in ./bin:"; ls -1 bin/ 2>/dev/null || true
exit 0
fi
# Create the upload key the first time. A PKCS12 keystore (the modern default)
# uses one password for both the store and the key, so we generate a single one.
if [[ ! -f "$ENV_FILE" ]]; then
echo "Creating signing details in .env. Keep this file private and backed up."
PW="$(python -c "import secrets; print(secrets.token_urlsafe(24))")"
{
echo "KEYSTORE_PATH=$KEYSTORE_FILE"
echo "KEYSTORE_ALIAS=$KEYSTORE_ALIAS"
echo "KEYSTORE_PASSWORD=$PW"
} > "$ENV_FILE"
chmod 600 "$ENV_FILE"
fi
# shellcheck disable=SC1091
source "$ENV_FILE"
if [[ ! -f "$KEYSTORE_FILE" ]]; then
echo "Creating the upload keystore: $KEYSTORE_FILE"
keytool -genkeypair -v \
-keystore "$KEYSTORE_FILE" \
-alias "$KEYSTORE_ALIAS" \
-keyalg RSA -keysize 2048 -validity 10000 \
-storepass "$KEYSTORE_PASSWORD" -keypass "$KEYSTORE_PASSWORD" \
-dname "CN=Ahmed Gad, OU=CoinTex, O=CoinTex, L=Unknown, ST=Unknown, C=US"
echo "Exporting upload_certificate.pem for Play Console"
keytool -export -rfc \
-keystore "$KEYSTORE_FILE" \
-alias "$KEYSTORE_ALIAS" \
-storepass "$KEYSTORE_PASSWORD" \
-file "$PROJECT_DIR/upload_certificate.pem"
echo "Back up cointex-upload.keystore and .env now. Without them you cannot"
echo "sign new uploads. See SIGNING.md for details."
fi
# Pass the keystore to python-for-android. The key password is the same as the
# store password because the keystore is in PKCS12 format.
export P4A_RELEASE_KEYSTORE="$KEYSTORE_FILE"
export P4A_RELEASE_KEYSTORE_PASSWD="$KEYSTORE_PASSWORD"
export P4A_RELEASE_KEYALIAS="$KEYSTORE_ALIAS"
export P4A_RELEASE_KEYALIAS_PASSWD="$KEYSTORE_PASSWORD"
# python-for-android builds one file type per run, so build the aab and the apk
# in two passes. Always leave buildozer.spec set back to aab when done.
set_artifact() {
sed -i "s/^android.release_artifact = .*/android.release_artifact = $1/" buildozer.spec
}
trap 'set_artifact aab' EXIT
echo "Building the release aab for Google Play"
set_artifact aab
buildozer android release
echo "Building the release apk for testing on a device"
set_artifact apk
buildozer android release
# Report the files.
echo ""
echo "Build finished. Files in ./bin:"
ls -1 bin/ 2>/dev/null || true
# Print package details from the apk using aapt from the downloaded SDK.
AAPT="$(find "$HOME/.buildozer" -type f -name aapt 2>/dev/null | sort | tail -1 || true)"
APK="$(ls -1 bin/*.apk 2>/dev/null | head -1 || true)"
if [[ -n "$AAPT" && -n "$APK" ]]; then
echo ""
echo "Details of $APK:"
"$AAPT" dump badging "$APK" | grep -E "package:|sdkVersion:|targetSdkVersion:|native-code:" || true
fi
echo ""
echo "Next steps:"
echo " Upload the .aab in ./bin to Google Play as a new release."
echo " If Play rejects the version code, raise android.numeric_version in"
echo " buildozer.spec and build again."
echo " For signing or lost key questions, see SIGNING.md."