blob: 476731b1b6d6d4f4406c228a9ce3ac8a85bcf060 (
plain) (
blame)
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
|
#!/bin/sh
# Build a signed release APK.
#
# Required environment:
# KEYSTORE_PATH absolute path to a JKS / PKCS12 keystore
# KEYSTORE_PASS password for the keystore
# KEY_ALIAS alias of the signing key inside the keystore
# KEY_PASS password for that key (often the same as KEYSTORE_PASS)
#
# Required tooling:
# Android build-tools 35.0.0 apksigner under ANDROID_SDK_ROOT or on PATH.
#
# Usage:
# scripts/build-apk
#
# Output: prints the absolute path of the signed APK and its sha256.
# The signed APK lives at app/build/outputs/apk/release/app-release.apk.
#
# This script does NOT generate a keystore. Generate one once with:
# keytool -genkey -v -keystore release.jks -alias scrcpy-android \
# -keyalg RSA -keysize 2048 -validity 10000
# and keep it outside the repo (it must never be committed).
set -eu
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
APK="$ROOT/app/build/outputs/apk/release/app-release.apk"
JAR="$ROOT/app/src/main/assets/scrcpy-server.jar"
require() {
name="$1"
eval "val=\${$name:-}"
if [ -z "$val" ]; then
echo "build-apk: \$$name is not set" >&2
echo " see the header of $0 for the required environment" >&2
exit 1
fi
}
require KEYSTORE_PATH
require KEYSTORE_PASS
require KEY_ALIAS
require KEY_PASS
if [ ! -f "$KEYSTORE_PATH" ]; then
echo "build-apk: keystore not found at $KEYSTORE_PATH" >&2
exit 1
fi
"$ROOT/scripts/check-wrapper"
"$ROOT/scripts/check-server"
echo "build-apk: gradle :app:assembleRelease"
cd "$ROOT"
./gradlew --no-daemon :app:assembleRelease
if [ ! -f "$APK" ]; then
echo "build-apk: gradle finished but $APK does not exist" >&2
exit 1
fi
SUM=$(sha256sum "$APK" | awk '{print $1}')
APKSIGNER=""
if [ -n "${ANDROID_SDK_ROOT:-}" ]; then
APKSIGNER="$ANDROID_SDK_ROOT/build-tools/35.0.0/apksigner"
if [ ! -x "$APKSIGNER" ]; then
APKSIGNER=""
fi
fi
if [ -z "$APKSIGNER" ] && command -v apksigner >/dev/null 2>&1; then
APKSIGNER=$(command -v apksigner)
fi
if [ -z "$APKSIGNER" ]; then
echo "build-apk: apksigner 35.0.0 is required" >&2
echo " set ANDROID_SDK_ROOT or put apksigner on PATH" >&2
exit 1
fi
echo "build-apk: apksigner verify"
"$APKSIGNER" verify --verbose --print-certs "$APK" | sed 's/^/ /'
echo "build-apk: $APK"
echo "build-apk: sha256 $SUM"
|