generated from amosproj/amos202Xss0Y-projname
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup_and_deploy.sh
142 lines (132 loc) · 3.99 KB
/
setup_and_deploy.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
#!/bin/bash
emulator_device_name="automotive"
detect_os() {
case $(uname | tr '[:upper:]' '[:lower:]') in
darwin*)
export os=osx
export path_android_sdk=${HOME}/Library/Android/sdk
export path_cmd_tools=${path_android_sdk}/cmdline-tools
export emulator=$path_android_sdk/emulator/emulator
export sdkmanager=${path_cmd_tools}/latest/bin/sdkmanager
export avdmanager=${path_cmd_tools}/latest/bin/avdmanager
;;
msys*)
export os=windows
export user="$(cut -d "\\" -f2 <<< $(whoami))"
export JAVA_HOME=C:/Program\ Files/Android/Android\ Studio/jre
export path_android_sdk=C:/Users/$user/AppData/Local/Android/sdk
export path_cmd_tools=${path_android_sdk}/cmdline-tools
export emulator=$path_android_sdk/emulator/emulator.exe
export sdkmanager=${path_cmd_tools}/latest/bin/sdkmanager.bat
export avdmanager=${path_cmd_tools}/latest/bin/avdmanager.bat
;;
*)
export os=notimplemented
;;
esac
export ANDROID_HOME=$path_android_sdk
export adb=$path_android_sdk/platform-tools/adb
}
confirm() {
if [ "$override" == "true" ]; then
true
else
read -r -p "${1} Are you sure? [y/N]" response
case "$response" in
[yY][eE][sS]|[yY])
true
;;
*)
false
;;
esac
fi
}
install_cmd_line_tools() {
echo "install command line tools"
if [ $os == "windows" ]; then
curl https://dl.google.com/android/repository/commandlinetools-win-9123335_latest.zip -J -o tools.zip
else
curl https://dl.google.com/android/repository/commandlinetools-mac-9123335_latest.zip -J -o tools.zip
fi
unzip tools.zip
mkdir -p $path_cmd_tools/latest/
cp -r cmdline-tools/* $path_cmd_tools/latest/
rm -rf cmdline-tools
rm tools.zip
}
copy_repo_cfg() {
echo "Copy custom url config into android folder"
if [ "$os" == "windows" ]; then
if [ ! -d "C:/Users/$user/.android/" ]; then
mkdir C:/Users/$user/.android/
fi
cp setup_files/repositories.cfg C:/Users/$user/.android/
else
cp setup_files/repositories.cfg ${HOME}/.android/
fi
}
install_automotive_system_image() {
if [ $(uname -m) == "arm64" ]; then
echo "using arm64 automotive image"
export sys_image="system-images;android-32;android-automotive-playstore;arm64-v8a"
$sdkmanager --install $sys_image --channel=3
else
echo "setting up custom url for x86_64 polestar automotive image"
confirm "This will overwrite all previously set up custom sdk urls!" && copy_repo_cfg
echo "using x86_64 polestar system image"
export sys_image="system-images;android-29;polestar_emulator;x86_64"
$sdkmanager --install $sys_image
fi
$sdkmanager --install "platforms;android-32"
$sdkmanager --install "build-tools;32.1.0-rc1"
$sdkmanager --install "sources;android-32"
$sdkmanager --install "extras;google;auto"
$sdkmanager --install "extras;google;simulators"
$sdkmanager --licenses
}
create_emulator_device() {
echo "create virtual device"
if [ $(uname -m) == "arm64" ]; then
device="automotive_1024p_landscape"
else
device="polestar_2_playstore"
fi
$avdmanager create avd -n $emulator_device_name -k $sys_image -d $device --force
}
build_and_deploy() {
cd App/
chmod +x gradlew
echo "prepare test"
./gradlew test
echo "test complete"
echo "build apk for install"
./gradlew assembleDebug
echo "start emulator"
$emulator -avd $emulator_device_name &
echo "wait for device boot"
$adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done; input keyevent 82'
echo "install apk"
$adb install ./automotive/build/outputs/apk/debug/automotive-debug.apk
echo "setup complete"
}
main() {
detect_os
if [ "$os" == "notimplemented" ]; then
echo "Operating system $os not supported"
exit 1
fi
if [ ! -d "$path_cmd_tools" ]; then
echo "No command line tools found"
confirm "Installing command line tools" && install_cmd_line_tools
fi
install_automotive_system_image
create_emulator_device
build_and_deploy
}
override="false"
if [ "$1" == "--full" ]; then
echo "full setup enabled..."
override="true"
fi
main