blob: b8e45e9d6f07b746cce8dd7b411a95f93241f42d [file] [log] [blame]
Justin Klaassen35f18222017-03-07 10:34:58 -08001#!/bin/bash
Justin Klaassenc4106382017-03-29 14:23:57 -04002
3# Attempt to set app_home
4# Resolve links: $0 may be a link
5prg="$0"
6# Need this for relative symlinks.
7while [ -h "$prg" ] ; do
8 ls=`ls -ld "$prg"`
9 link=`expr "$ls" : '.*-> \(.*\)$'`
10 if expr "$link" : '/.*' > /dev/null; then
11 prg="$link"
12 else
13 prg=`dirname "$prg"`"/$link"
14 fi
15done
16saved="`pwd`"
17cd "`dirname \"$prg\"`" >/dev/null
18app_home="`pwd -P`"
19cd "$saved" >/dev/null
20
21ANDROID_WRAPPER_BIN_DIR=${ANDROID_WRAPPER_BIN_DIR:-$app_home/bin}
22ANDROID_WRAPPER_SDK_TIMEOUT=${ANDROID_WRAPPER_SDK_TIMEOUT:-20}
23
24cat <<< \
25"*************************************************************************
26The \"android\" command is deprecated.
27For manual SDK, AVD, and project management, please use Android Studio.
28For command-line tools, use tools/bin/sdkmanager and tools/bin/avdmanager
29*************************************************************************"
30
31function usage {
32 echo "Invalid or unsupported command \"$@\""
33 echo
34 echo "Supported commands are:"
35 echo "android list target"
36 echo "android list avd"
37 echo "android list device"
38 echo "android create avd"
39 echo "android move avd"
40 echo "android delete avd"
41 echo "android list sdk"
42 echo "android update sdk"
43 exit 2
44}
45
46function matches {
47 verbs=$1
48 objects=$2
49 verb=""
50 object=""
51 shift 2
52
53 for arg in "$@"; do
54 if [[ $arg =~ ^- ]]; then
55 continue
56 fi
57 if [[ -z $verb && $verbs =~ ( |^)$arg( |$) ]]; then
58 verb=$arg
59 continue
60 fi
61 if [[ -n $verb && $objects =~ ( |^)$arg( |$) ]]; then
62 object=$arg
63 break
64 fi
65 break
66 done
67 return $([[ -n $verb && -n $object ]])
68}
69
70function echo_and_exec {
71 echo "Running $@"
72 echo
73 exec $@
74}
75
76function parse_filter {
77 local IFS=,
78 for filter in $1; do
79 if [[ $filter == tool || $filter == platform-tool || $filter == doc ]]; then
80 command+=( "$args ${filter}s" )
81 elif [[ $filter == tools || $filter == platform-tools ]]; then
82 command+=( "$args ${filter}" )
83 elif [[ $filter =~ ^lldb ]]; then
84 command+=( "$args ${filter/-/;}" )
85 elif [[ $filter =~ ^build-tools ]]; then
86 command+=( "$args ${filter/build-tools-/build-tools;}" )
87 elif [[ $filter == ndk ]]; then
88 command+=( "$args ndk-bundle" )
89 elif [[ $filter =~ ^android- ]]; then
90 command+=( "$args platforms;$filter" )
Justin Klaassena08a4b32017-09-05 14:15:09 -040091 elif [[ $filter =~ ^extra- ]]; then
92 tmp=${filter//-/;}
93 command+=( "$args ${tmp/extra/extras}" )
Justin Klaassenc4106382017-03-29 14:23:57 -040094 else
95 echo Filter $filter not supported
96 exit 2
97 fi
98 done
99}
100
101function confirm_try_sdk {
102 for arg in "$@"; do
103 if [[ $arg == --use-sdk-wrapper ]]; then
104 return 0
105 fi
106 done
107 if [[ -n $USE_SDK_WRAPPER ]]; then
108 return 0
109 fi
110 read -t $ANDROID_WRAPPER_SDK_TIMEOUT -p "\"android\" SDK commands can be translated to sdkmanager commands on a best-effort basis.
111Continue? (This prompt can be suppressed with the --use-sdk-wrapper command-line argument
112or by setting the USE_SDK_WRAPPER environment variable) [y/N]: " trysdkresponse
113 if (( $? > 128 )); then
114 echo "Timed out waiting for input."
115 echo "To suppress this prompt, run with --use-sdk-wrapper or set USE_SDK_WRAPPER."
116 exit 1
117 fi
118 if [[ ${trysdkresponse,,} == y ]]; then
119 return 0
120 fi
121 echo Aborted
122 exit 1
123}
124
125avd_verbs="list create move delete"
126avd_objects="avd target device"
127
128if matches "$avd_verbs" "$avd_objects" "$@"; then
129 echo_and_exec "$ANDROID_WRAPPER_BIN_DIR/avdmanager" "$@"
130fi
131
132sdk_verbs="list update"
133sdk_objects="sdk"
134
135if matches "$sdk_verbs" "$sdk_objects" "$@"; then
136 confirm_try_sdk $@
137 if [[ $verb == list ]]; then
138 echo_and_exec "$ANDROID_WRAPPER_BIN_DIR/sdkmanager" --list --verbose
139 fi
140 if [[ $verb == update ]]; then
141 command=( "$ANDROID_WRAPPER_BIN_DIR/sdkmanager" )
142 prev=""
143 update_all=1
144 for arg in "$@"; do
145 if [[ $arg == --use-sdk-wrapper || $arg == $verb || $arg == $object ]]; then
146 continue
147 elif [[ $arg == -n ]]; then
148 echo "update sdk -n is not supported"
149 exit 2
150 elif [[ $arg == -s || $arg == --no-https ]]; then
151 command+=("--no_https")
152 elif [[ $arg == -a || $arg == --all ]]; then
153 command+=("--include_obsolete")
154 elif [[ $arg == -p || $arg == --obsolete || $arg == -u || $arg == --no-ui || $arg == --proxy-host ||
155 $arg == --proxy-port || $arg == -t || $arg == --filter ]]; then
156 :
157 elif [[ $prev == --proxy-host ]]; then
158 command+=("--proxy=http" "--proxy_host=$arg")
159 elif [[ $prev == --proxy-port ]]; then
160 command+=("--proxy_port=$arg")
161 elif [[ $prev == -t || $prev == --filter ]]; then
162 update_all=
163 parse_filter $arg
164 else
165 echo Unrecognized argument $arg
166 exit 2
167 fi
168
169 prev=$arg
170 done
171 if [[ -n $update_all ]]; then
172 command+=("--update")
173 fi
174 echo_and_exec ${command[@]}
175 fi
176fi
177
178usage $@