How to install Android SDK Build Tools on the comm

2019-01-05 06:35发布

I want to setup the Android dev environment from command line, and encounter the following issue:

wget http://dl.google.com/android/android-sdk_r22.0.5-linux.tgz

after extract the file, run

tools/android update sdk --no-ui

However, it is too slow on running

Fetching https://dl-ssl.google.com/android/repository/addons_list-2.xml

The result is that nothing in folder build-tools, and I want is aapt and apkbuilder, since I want to build apk from command line without ant.

18条回答
Luminary・发光体
2楼-- · 2019-01-05 07:03

Download android SDK from developer.android.com (its currently a 149mb file for windows OS). It is worthy of note that android has removed the sdkmanager GUI but has a command line version of the sdkmanager in the bin folder which is located inside the tools folder.

  1. When inside the bin folder, hold down the shift key, right click, then select open command line here. Shift+right click >> open command line here.
  2. When the command line opens, type sdkmanager click enter.
  3. Then run type sdkmanager (space), double hyphen (--), type list Sdkmanager --list (this lists all the packages in the SDK manager)
  4. Type sdkmanager (space) then package name, press enter. Eg. sdkmanager platform-tools (press enter) It will load licence agreement. With options (y/n). Enter y to accept and it will download the package you specified.

I hope this helps. :)

查看更多
冷血范
3楼-- · 2019-01-05 07:05

Most of the answers seem to ignore the fact that you may need to run the update in a headless environment with no super user rights, which means the script has to answer all the y/n license prompts automatically.

Here's the example that does the trick.

FILTER=tool,platform,android-20,build-tools-20.0.0,android-19,android-19.0.1

( sleep 5 && while [ 1 ]; do sleep 1; echo y; done ) \
    | android update sdk --no-ui --all \
    --filter ${FILTER}

No matter how many prompts you get, all of those will be answered. This while/sleep loop looks like simulation of the yes command, and in fact it is, well almost. The problem with yes is that it floods stdout with 'y' and there is virtually no delay between sending those characters and the version I had to deal with had no timeout option of any kind. It will "pollute" stdout and the script will fail complaining about incorrect input. The solution is to put a delay between sending 'y' to stdout, and that's exactly what while/sleep combo does.

expect is not available by default on some linux distros and I had no way to install it as part of my CI scripts, so had to use the most generic solution and nothing can be more generic than simple bash script, right?

As a matter of fact, I blogged about it (NSBogan), check it out for more details here if you are interested.

查看更多
爱情/是我丢掉的垃圾
4楼-- · 2019-01-05 07:05

Inspired from answers by @i4niac & @Aurélien Lambert, this is what i came up with

csv_update_numbers=$(./android list sdk --all | grep 'Android SDK Build-tools' | grep -v 'Obsolete' | sed 's/\(.*\)\- A.*/\1/'|sed '/^$/d'|sed -e 's/^[ \t]*//'| tr '\n' ',')
csv_update_numbers_without_trailing_comma=${csv_update_numbers%?}

( sleep 5 && while [ 1 ]; do sleep 1; echo y; done ) \
    | ./android update sdk --all -u -t $csv_update_numbers_without_trailing_comma

Explanation

  • get a comma separated list of numbers which are the indexes of build tools packages in the result of android list sdk --all command (Ignoring obsolete packages).
  • keep throwing 'y's at the terminal every few miliseconds to accept the licenses.
查看更多
走好不送
5楼-- · 2019-01-05 07:09

As stated in other responses, the build tools requires the --all flag to be installed. You also better use a -t filter flag to avoid installing ALL the packages but there is no way to filter all the build tools.

There are already features requests for these two points in AOSP bug tracker. Feel free to vote for them, this might make them happen some day:

查看更多
仙女界的扛把子
6楼-- · 2019-01-05 07:10

ADB Build-Tools Will Not be downloaded automatically, by command android update sdk --no-ui

So for installing Buil-Tool type (in console):

android list sdk --all

Remember the number that is listed before the item and execute the following:

android update sdk -u --all --filter <number>

commands should be typed in /YourFolder/android-sdk-linux/tools

Also for remote folder (server opened by ssh for example) type:

**./android** list sdk --all
**./android** update sdk -u --all --filter <number>

For simple list of ADB packages type in terminal:

android list sdk

for install all packages:

android update sdk --no-ui

Or with filters (comma is separator):

android update sdk --no-ui --filter 3,5,8,14
查看更多
Anthone
7楼-- · 2019-01-05 07:10

Build tools could not be downloaded automatically by default as Nate said in https://stackoverflow.com/a/19416222/1104031 post.

But I wrote small tool that make everything for you

I used "expect" tool as danb in https://stackoverflow.com/a/17863931/1104031 post. You only need android-sdk and python27, expect.

This script will install all build tools, all sdks and everything you need for automated build:

import subprocess,re,sys

w = subprocess.check_output(["android", "list", "sdk", "--all"])
lines = w.split("\n")
tools = filter(lambda x: "Build-tools" in x, lines)
filters = []
for tool in tools:
  m = re.search("^\s+([0-9]+)-", tool)
  tool_no = m.group(1)
  filters.append(tool_no)

if len(filters) == 0:
  raise Exception("Not found build tools")


filters.extend(['extra', 'platform', 'platform-tool', 'tool'])

filter = ",".join(filters)

expect= '''set timeout -1;
spawn android update sdk --no-ui --all --filter %s;
expect {
  "Do you accept the license" { exp_send "y\\r" ; exp_continue }
  eof
}''' % (filter)

print expect

ret = subprocess.call(["expect", "-c", expect])
sys.exit(ret)
查看更多
登录 后发表回答