forked from wchen342/ungoogled-chromium-android
-
Notifications
You must be signed in to change notification settings - Fork 44
/
bundle_generate_apk.sh
executable file
·149 lines (132 loc) · 5.1 KB
/
bundle_generate_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
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
149
#!/bin/bash
# Modified from Vanadium
set -o errexit -o nounset -o pipefail
SCRIPT_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
source "${SCRIPT_PATH}/.build_config"
KEYSTORE=$PWD/../../uc_keystore/uc-release-key.keystore
KEYSTORE_PASS=$PWD/../../uc_keystore/keystore_pass
APKSIGNER=$PWD/third_party/android_sdk/public/build-tools/31.0.0/apksigner
BUNDLETOOL=$PWD/build/android/gyp/bundletool.py
AAPT2=$PWD/third_party/android_build_tools/aapt2/aapt2
# Argument parser from https://stackoverflow.com/questions/192249/how-do-i-parse-command-line-arguments-in-bash/29754866#29754866
# -allow a command to fail with !’s side effect on errexit
# -use return value from ${PIPESTATUS[0]}, because ! hosed $?
! getopt --test > /dev/null
if [[ ${PIPESTATUS[0]} -ne 4 ]]; then
echo 'I’m sorry, `getopt --test` failed in this environment.'
exit 1
fi
OPTIONS=o:a:t:
LONGOPTS=output:,arch:,target:
# -regarding ! and PIPESTATUS see above
# -temporarily store output to be able to check for errors
# -activate quoting/enhanced mode (e.g. by writing out “--options”)
# -pass arguments only via -- "$@" to separate them correctly
! PARSED=$(getopt --options=$OPTIONS --longoptions=$LONGOPTS --name "$0" -- "$@")
if [[ ${PIPESTATUS[0]} -ne 0 ]]; then
# e.g. return value is 1
# then getopt has complained about wrong arguments to stdout
exit 2
fi
# read getopt’s output this way to handle the quoting right:
eval set -- "$PARSED"
OUTPUT=- TARGET=-
# now enjoy the options in order and nicely split until we see --
while true; do
case "$1" in
-o|--output)
OUTPUT="$2"
shift 2
;;
-a|--arch)
ARCH="$2"
shift 2
;;
-t|--target)
TARGET="$2"
shift 2
;;
--)
shift
break
;;
*)
echo "Programming error"
exit 3
;;
esac
done
if [[ "$ARCH" != "arm64" ]] && [[ "$ARCH" != "arm" ]] && [[ "$ARCH" != "x86" ]]; then
echo "Wrong architecture"
exit 4
fi
if [[ "$TARGET" != "$chrome_modern_target" ]] && [[ "$TARGET" != "$trichrome_chrome_bundle_target" ]] && [[ "$TARGET" != "$trichrome_chrome_64_bundle_target" ]] \
&& [[ "$TARGET" != "$trichrome_chrome_apk_target" ]] && [[ "$TARGET" != "$trichrome_chrome_64_apk_target" ]] \
&& [[ "$TARGET" != "$trichrome_webview_target" ]] && [[ "$TARGET" != "$trichrome_webview_64_target" ]]; then
echo "Wrong target"
exit 4
fi
if [[ ! -d $OUTPUT ]]; then
echo "Output folder doesn't exist"
exit 1
fi
case "$TARGET" in
"$chrome_modern_target")
FILENAME="ChromeModernPublic"
FILENAME_OUT="ChromeModernPublic"
;;
"$trichrome_chrome_bundle_target")
FILENAME="TrichromeChrome"
FILENAME_OUT="TrichromeChrome"
;;
"$trichrome_chrome_64_bundle_target")
FILENAME="TrichromeChrome64"
FILENAME_OUT="TrichromeChrome"
;;
"$trichrome_chrome_apk_target")
FILENAME="TrichromeChrome"
FILENAME_OUT="TrichromeChrome"
;;
"$trichrome_chrome_64_apk_target")
FILENAME="TrichromeChrome64"
FILENAME_OUT="TrichromeChrome"
;;
"$trichrome_webview_target")
FILENAME="TrichromeWebView"
FILENAME_OUT="TrichromeWebView"
;;
"$trichrome_webview_64_target")
FILENAME="TrichromeWebView64"
FILENAME_OUT="TrichromeWebView"
;;
*)
echo "Filename parsing error"
exit 3
;;
esac
echo "output: $OUTPUT, arch: $ARCH, target: $TARGET, filename: $FILENAME"
cd $OUTPUT/apks
rm -rf release
mkdir release
cd release
if [[ "$TARGET" != "$trichrome_webview_target" ]] && [[ "$TARGET" != "$trichrome_webview_64_target" ]] \
&& [[ "$TARGET" != "$trichrome_chrome_apk_target" ]] && [[ "$TARGET" != "$trichrome_chrome_64_apk_target" ]]; then
$BUNDLETOOL build-apks --aapt2 $AAPT2 --bundle ../"$FILENAME".aab --output "$FILENAME".apks --mode=universal --ks $KEYSTORE --ks-pass file:$KEYSTORE_PASS --ks-key-alias uc
unzip "$FILENAME".apks universal.apk
mv universal.apk "${FILENAME_OUT}".apk
$APKSIGNER sign --ks $KEYSTORE --ks-pass file:$KEYSTORE_PASS --ks-key-alias uc --in "${FILENAME_OUT}".apk --out "${FILENAME_OUT}".apk
fi
if [[ "$TARGET" == "$trichrome_chrome_bundle_target" ]] || [[ "$TARGET" == "$trichrome_webview_target" ]] || [[ "$TARGET" == "$trichrome_chrome_apk_target" ]]; then
for app in TrichromeLibrary TrichromeWebView TrichromeChrome; do
if [ -f "../${app}.apk" ]; then
$APKSIGNER sign --ks $KEYSTORE --ks-pass file:$KEYSTORE_PASS --ks-key-alias uc --in "../${app}.apk" --out "${app}.apk"
fi
done
fi
if [[ "$TARGET" == "$trichrome_chrome_64_bundle_target" ]] || [[ "$TARGET" == "$trichrome_webview_64_target" ]] || [[ "$TARGET" == "$trichrome_chrome_64_apk_target" ]]; then
for app in TrichromeLibrary TrichromeWebView TrichromeChrome; do
if [ -f "../${app}64.apk" ]; then
$APKSIGNER sign --ks $KEYSTORE --ks-pass file:$KEYSTORE_PASS --ks-key-alias uc --in "../${app}64.apk" --out "${app}.apk"
fi
done
fi