如何在命令行上安装Android SDK Build Tools?

本文翻译自:How to install Android SDK Build Tools on the command line?

I want to setup the Android dev environment from command line, and encounter the following issue: 我想从命令行设置Android dev环境,遇到以下问题:

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. 结果是文件夹构建工具中没有任何内容,我想要的是aapt和apkbuilder,因为我想在没有ant的情况下从命令行构建apk。


#1楼

参考:https://stackoom.com/question/1dn80/如何在命令行上安装Android-SDK-Build-Tools


#2楼

However, it is too slow on running 但是,跑步太慢了

Yes, I've had the same problem. 是的,我遇到了同样的问题。 Some of the file downloads are extremely slow (or at least they have been in the last couple of days). 一些文件下载非常慢(或者至少它们已经过去几天)。 If you want to download everything there's not a lot you can do about that. 如果你想下载所有内容,你可以做很多事情。

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. 结果是文件夹构建工具中没有任何内容,我想要的是aapt和apkbuilder,因为我想在没有ant的情况下从命令行构建apk。

Did you let it run to completion? 你让它完成了吗?

One thing you can do is filter the packages that are being downloaded using the -t switch. 您可以做的一件事是使用-t开关过滤正在下载的软件包。

For example: 例如:

tools/android update sdk --no-ui -t platform-tool

When I tried this the other day I got version 18.0.0 of the build tools installed. 有一天,当我尝试使用此版本时,我安装了18.0.0版本的构建工具。 For some reason the latest version 18.0.1 is not included by this filter and the only way to get it was to install everything with the --all switch. 由于某种原因,此过滤器不包含最新版本18.0.1,获得它的唯一方法是使用--all开关安装所有内容。


#3楼

By default, the SDK Manager from the command line does not include the build tools in the list. 默认情况下,命令行中的SDK Manager不包含列表中的构建工具。 They're in the "obsolete" category. 他们处于“过时”类别。 To see all available downloads, use 要查看所有可用下载,请使用

android list sdk --all

And then to get one of the packages in that list from the command line, use: 然后从命令行获取该列表中的一个包,使用:

android update sdk -u -a -t <package no.>

Where -u stands for --no-ui, -a stands for --all and -t stands for --filter. 其中-u代表--no-ui,-a代表--all,-t代表--filter。

If you need to install multiple packages do: 如果需要安装多个包,请执行以下操作:

android update sdk -u -a -t 1,2,3,4,..,n

Where 1,2,..,n is the package number listed with the list command above 其中1,2,..,n是上面列出命令列出的包号


#4楼

Build tools could not be downloaded automatically by default as Nate said in https://stackoverflow.com/a/19416222/1104031 post. Nate在https://stackoverflow.com/a/19416222/1104031帖子中说,默认情况下无法自动下载构建工具。

But I wrote small tool that make everything for you 但我写了一个小工具,为你做一切

I used "expect" tool as danb in https://stackoverflow.com/a/17863931/1104031 post. 我在https://stackoverflow.com/a/17863931/1104031帖子中使用了“expect”工具作为danb。 You only need android-sdk and python27 , expect . 你只需要Android的SDK和python27expect

This script will install all build tools, all sdks and everything you need for automated build: 此脚本将安装所有构建工具,所有sdks以及自动构建所需的一切:

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)

#5楼

ADB Build-Tools Will Not be downloaded automatically, by command android update sdk --no-ui ADB Build-Tools不会通过命令android update sdk --no-ui自动下载

So for installing Buil-Tool type (in console): 所以安装Buil-Tool类型(在控制台中):

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 命令应该输入/ YourFolder / android-sdk-linux / tools

Also for remote folder (server opened by ssh for example) type: 也适用于远程文件夹(例如由ssh打开的服务器)类型:

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

For simple list of ADB packages type in terminal: 对于简单的ADB包列表,请在终端中输入:

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

#6楼

As mentioned in other answers, you can use the --filter option to limit the installed packages: 如其他答案中所述,您可以使用--filter选项来限制已安装的软件包:

android update sdk --filter ...

The other answers don't mention that you can use constant string identifiers instead of indexes (which will change) for the filter options. 其他答案没有提到您可以使用常量字符串标识符而不是过滤器选项的索引(将更改)。 This is helpful for unattended or scripted installs. 这对无人参与或脚本安装很有帮助。 Man for --filter option: 男人--filter选项:

... This also accepts the identifiers returned by 'list sdk --extended'. ...这也接受'list sdk --extended'返回的标识符。

android list sdk --all --extended : android list sdk --all --extended

Packages available for installation or update: 97
----------
id: 1 or "tools"
     Type: Tool
     Desc: Android SDK Tools, revision 22.6.2
----------
id: 2 or "platform-tools"
     Type: PlatformTool
     Desc: Android SDK Platform-tools, revision 19.0.1
----------
id: 3 or "build-tools-19.0.3"
     Type: BuildTool
     Desc: Android SDK Build-tools, revision 19.0.3

Then you can use the string ids as the filter options to precisely specify the versions you want: 然后,您可以使用字符串ID作为过滤器选项来精确指定所需的版本:

android update sdk --filter tools,platform-tools,build-tools-19.0.3 etc android update sdk --filter tools,platform-tools,build-tools-19.0.3

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值