-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathstep.sh
72 lines (57 loc) · 2.03 KB
/
step.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
#!/bin/bash
#set -ex
#=======================================
# Validations
#=======================================
validateApkName(){
if [[ -z "${apk_name// }" ]]; then
apk_name="universal"
fi
apk_name="${apk_name//.apk}"
}
#=======================================
# Main
#=======================================
#step_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
temp_path=$PWD
echo "building universal apk path"
echo "Getting app bundle from ${aab_path}"
echo "Signing with ${keystore_url} key and alias ${keystore_alias}"
validateApkName
echo "apk name ${apk_name}"
bundletool="${temp_path}/bundletool.jar"
keystore="${temp_path}/keystore.jks"
source="https://github.com/google/bundletool/releases/download/0.8.0/bundletool-all-0.8.0.jar"
# Building
aab_output_path="${temp_path}/output/bundle"
aab_output="${aab_output_path}/${apk_name}.apks"
apk_output_path="${temp_path}/output/apk"
apk_output="${apk_output_path}/${apk_name}.apk"
mkdir -p "${aab_output_path}" &
mkdir -p "${apk_output_path}" &
wait
echo "Downloading keystore"
curl -o "keystore.jks" "${keystore_url}"
wait
echo "Downloading bundle tool"
wget -nv "${source}" --output-document="${bundletool}" &
wait
echo "Extracting bundle apks"
exec java -jar "${bundletool}" build-apks --bundle="${aab_path}" --output="${aab_output}" --mode=universal --ks=${keystore} --ks-pass=pass:"${keystore_password}" --ks-key-alias="${keystore_alias}" --key-pass=pass:"${keystore_alias_password}" &
wait
echo "APK created in ${apk_output_path}"
exec unzip ${aab_output} -d ${apk_output_path} &
wait
# rename universal.apk to the given name
mv ${apk_output_path}/universal.apk ${apk_output} &
wait
# move the apk to the alternative output path
if [[ -n "${apk_output_dir// }" ]]; then
mv ${apk_output} ${apk_output_dir}/${apk_name}.apk &
apk_output="${apk_output_dir}/${apk_name}.apk"
apk_output_path="${apk_output_dir}"
fi
wait
envman add --key BITRISE_APK_PATH --value ${apk_output}
envman add --key BITRISE_APK_DIR --value ${apk_output_path}
exit 0