Android O SDK.
[android_tools.git] / sdk / tools / android
blob40d9c3a85931b79fdddcf560ba4d88a8d5083510
1 #!/bin/bash
3 # Attempt to set app_home
4 # Resolve links: $0 may be a link
5 prg="$0"
6 # Need this for relative symlinks.
7 while [ -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"
15 done
16 saved="`pwd`"
17 cd "`dirname \"$prg\"`" >/dev/null
18 app_home="`pwd -P`"
19 cd "$saved" >/dev/null
21 ANDROID_WRAPPER_BIN_DIR=${ANDROID_WRAPPER_BIN_DIR:-$app_home/bin}
22 ANDROID_WRAPPER_SDK_TIMEOUT=${ANDROID_WRAPPER_SDK_TIMEOUT:-20}
24 cat <<< \
25 "*************************************************************************
26 The \"android\" command is deprecated.
27 For manual SDK, AVD, and project management, please use Android Studio.
28 For command-line tools, use tools/bin/sdkmanager and tools/bin/avdmanager
29 *************************************************************************"
31 function 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
46 function matches {
47 verbs=$1
48 objects=$2
49 verb=""
50 object=""
51 shift 2
53 for arg in "$@"; do
54 if [[ $arg =~ ^- ]]; then
55 continue
57 if [[ -z $verb && $verbs =~ ( |^)$arg( |$) ]]; then
58 verb=$arg
59 continue
61 if [[ -n $verb && $objects =~ ( |^)$arg( |$) ]]; then
62 object=$arg
63 break
65 break
66 done
67 return $([[ -n $verb && -n $object ]])
70 function echo_and_exec {
71 echo "Running $@"
72 echo
73 exec $@
76 function 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" )
91 else
92 echo Filter $filter not supported
93 exit 2
95 done
98 function confirm_try_sdk {
99 for arg in "$@"; do
100 if [[ $arg == --use-sdk-wrapper ]]; then
101 return 0
103 done
104 if [[ -n $USE_SDK_WRAPPER ]]; then
105 return 0
107 read -t $ANDROID_WRAPPER_SDK_TIMEOUT -p "\"android\" SDK commands can be translated to sdkmanager commands on a best-effort basis.
108 Continue? (This prompt can be suppressed with the --use-sdk-wrapper command-line argument
109 or by setting the USE_SDK_WRAPPER environment variable) [y/N]: " trysdkresponse
110 if (( $? > 128 )); then
111 echo "Timed out waiting for input."
112 echo "To suppress this prompt, run with --use-sdk-wrapper or set USE_SDK_WRAPPER."
113 exit 1
115 if [[ ${trysdkresponse,,} == y ]]; then
116 return 0
118 echo Aborted
119 exit 1
122 avd_verbs="list create move delete"
123 avd_objects="avd target device"
125 if matches "$avd_verbs" "$avd_objects" "$@"; then
126 echo_and_exec "$ANDROID_WRAPPER_BIN_DIR/avdmanager" "$@"
129 sdk_verbs="list update"
130 sdk_objects="sdk"
132 if matches "$sdk_verbs" "$sdk_objects" "$@"; then
133 confirm_try_sdk $@
134 if [[ $verb == list ]]; then
135 echo_and_exec "$ANDROID_WRAPPER_BIN_DIR/sdkmanager" --list --verbose
137 if [[ $verb == update ]]; then
138 command=( "$ANDROID_WRAPPER_BIN_DIR/sdkmanager" )
139 prev=""
140 update_all=1
141 for arg in "$@"; do
142 if [[ $arg == --use-sdk-wrapper || $arg == $verb || $arg == $object ]]; then
143 continue
144 elif [[ $arg == -n ]]; then
145 echo "update sdk -n is not supported"
146 exit 2
147 elif [[ $arg == -s || $arg == --no-https ]]; then
148 command+=("--no_https")
149 elif [[ $arg == -a || $arg == --all ]]; then
150 command+=("--include_obsolete")
151 elif [[ $arg == -p || $arg == --obsolete || $arg == -u || $arg == --no-ui || $arg == --proxy-host ||
152 $arg == --proxy-port || $arg == -t || $arg == --filter ]]; then
154 elif [[ $prev == --proxy-host ]]; then
155 command+=("--proxy=http" "--proxy_host=$arg")
156 elif [[ $prev == --proxy-port ]]; then
157 command+=("--proxy_port=$arg")
158 elif [[ $prev == -t || $prev == --filter ]]; then
159 update_all=
160 parse_filter $arg
161 else
162 echo Unrecognized argument $arg
163 exit 2
166 prev=$arg
167 done
168 if [[ -n $update_all ]]; then
169 command+=("--update")
171 echo_and_exec ${command[@]}
175 usage $@