-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_apk
75 lines (64 loc) · 1.6 KB
/
build_apk
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
#!/bin/bash
if [ ! $1 ]; then
echo android build script
echo usage build_apk dir_path [options]
echo
echo -c --clean cleanup apk files created except the final signed veriosn
echo -i --install install the apk file after the build
echo -f --force overwrite existing apk file
echo "-n --name specify name for the apk file"
exit 0
fi
dir_name=$1
NAME=$1
while [ $1 ]; do
shift # past the name of dir and future options
case $1 in
-c|--clean-up)
CLEAN=true
;;
-i|--install)
INSTALL=true
;;
-f|--force)
FORCE=true
;;
-n|--name)
NAME=$2
shift
;;
esac
done
# if dir does notexist then program will terminate
if [ ! -d $dir_name ]; then
echo [x] source apk directory does not exist
exit 1
fi
# check if the file by the same name exist
if [ -f $NAME.apk ] && [ ! $FORCE ]; then
echo [x] $dir_name.apk already exist use -f to overwrite (not recommended)
echo or specify new name with -n
exit 2
fi
output=$(apktool b $dir_name -o $NAME.apk)
# if apk file not built means an error has occured
if [ ! -f $NAME.apk ]; then
echo [x] ERROR while building apk
echo [x] APKTOOL output as follows
echo $output
exit 3
fi
echo [-] $NAME.apk has been successfully built
# install the apk file to specified android device
if [ $ANDROID_DEVICE ] && [ $INSTALL ]; then
echo [?] waiting for $ANDROID_DEVICE to respond
adb -s $ANDROID_DEVICE wait-for-device
echo [o] $ANDROID_DEVICE has responded
# need to sign the apk to install
$TOOL_KIT/android/sign_apk $NAME.apk
echo [o] finished signing apk
adb -s $ANDROID_DEVICE install $NAME-signed-za.apk
fi
if [ $CLEAN ]; then
rm TEMP
fi