我想从命令行设置Android开发环境,遇到以下问题:

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

解压完成后,运行

tools/android update sdk --no-ui

但是,它跑起来太慢了

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

结果是在文件夹build-tools中什么都没有,我想要的是apapt和apkbuilder,因为我想从命令行构建apk而没有ant。


当前回答

Android SDK Tools 25.2.3版本(及更高版本)包含了新的工具sdkmanager,它简化了从命令行安装构建工具的任务。 它位于android_sdk/tools/bin文件夹中。

用法(来自文档):

List installed and available packages: sdkmanager --list [options] \ [--channel=channel_id] // Channels: 0 (stable), 1 (beta), 2 (dev), or 3 (canary) Use the channel option to include a package from a channel up to and including channel_id. For example, specify the canary channel to list packages from all channels. Install packages: sdkmanager packages [options] The packages argument is an SDK-style path, wrapped in quotes (for example, "build-tools;25.0.0" or "platforms;android-25"). You can pass multiple package paths, separated with a space, but they must each be wrapped in their own set of quotes.

示例用法(在我的Mac上):

alex@mbpro:~/sdk/tools/bin$ ls ../../build-tools/  
25.0.0/   
alex@mbpro:~/sdk/tools/bin$ ./sdkmanager "build-tools;25.0.2"  
done   
alex@mbpro:~/sdk/tools/bin$ ls ../../build-tools/  
25.0.0/ 25.0.2/

您还可以指定各种选项,例如强制所有连接使用HTTP(——no_https),或者为了使用代理服务器(——proxy_host=address和——proxy_port=port)。

要检查可用选项,使用——help标志。在我的机器(Mac)上,输出如下:

alex@mbpro:~/sdk/tools/bin$ ./sdkmanager --help
Usage: 
  sdkmanager [--uninstall] [<common args>] \
    [--package_file <package-file>] [<packages>...]
  sdkmanager --update [<common args>]
  sdkmanager --list [<common args>]

In its first form, installs, or uninstalls, or updates packages.
    <package> is a sdk-style path (e.g. "build-tools;23.0.0" or 
             "platforms;android-23").
    <package-file> is a text file where each line is a sdk-style path
                   of a package to install or uninstall.
    Multiple --package_file arguments may be specified in combination
     with explicit paths.
In its second form (with --update), currently installed packages are
    updated to the latest version.
In its third form, all installed and available packages are printed out.

Common Arguments:
    --sdk_root=<sdkRootPath>: Use the specified SDK root instead of the SDK containing this tool
    --channel=<channelId>: Include packages in channels up to <channelId>.
                           Common channels are:
                           0 (Stable), 1 (Beta), 2 (Dev), and 3 (Canary).

    --include_obsolete: With --list, show obsolete packages in the
                        package listing. With --update, update obsolete
                        packages as well as non-obsolete.
    --no_https: Force all connections to use http rather than https.
    --proxy=<http | socks>: Connect via a proxy of the given type.
    --proxy_host=<IP or DNS address>: IP or DNS address of the proxy to use.
    --proxy_port=<port #>: Proxy port to connect to.

* If the env var REPO_OS_OVERRIDE is set to "windows",
  "macosx", or "linux", packages will be downloaded for that OS.

其他回答

但是,它跑起来太慢了

是的,我也遇到过同样的问题。有些文件下载非常慢(至少在过去几天是这样)。如果你想下载所有的东西,你可以做的不多。

结果是在文件夹build-tools中什么都没有,我想要的是apapt和apkbuilder,因为我想从命令行构建apk而没有ant。

你让它跑完吗?

您可以做的一件事是使用-t开关过滤正在下载的包。

例如:

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

当我前几天尝试这样做时,我安装了18.0.0版本的构建工具。由于某种原因,最新版本18.0.1没有包含在这个过滤器中,获得它的唯一方法是使用——all开关安装所有东西。

我刚刚花了很长时间通过命令行安装android sdk依赖项,由于工具和在线附带的文档严重缺乏,我想我将在这里发布我发现的东西。

我正在使用android sdk r24.4.1 for linux。你可以运行两个命令来列出可用的包:

Android列表SDK

更详尽的是:

Android列表SDK——所有

对于上面的每个命令,特定包的包号不同!例如,前者将包API 23.1修订版3列为包#3,后者将其列为包#29。

现在,使用android命令有两种不同的安装方式。

Tools /android update SDK——no-ui——filter <package number>

and

Tools /android update SDK -u -a -t <包号>

假设每个安装命令都可以将package #作为参数,那么使用哪个包号呢?经过大量的网上搜索和尝试和错误,我发现

Android更新SDK——no-ui——过滤器使用Android列表SDK的包号

and

Android update SDK -u -a -t使用Android list SDK——all中的包号

换句话说,要安装API 23.1修订版3,你可以这样做:

Android更新SDK—no-ui—filter 3

or

Android更新SDK -u -a -t 29

很疯狂,但很有效。

如果你安装了sdkmanager(我使用MAC)

执行sdkmanager——list命令列出可用的包。

如果要安装构建工具,请从可用软件包列表中复制首选版本。

要安装首选版本,请运行

sdkmanager "build-tools;27.0.3"

Android SDK Tools 25.2.3版本(及更高版本)包含了新的工具sdkmanager,它简化了从命令行安装构建工具的任务。 它位于android_sdk/tools/bin文件夹中。

用法(来自文档):

List installed and available packages: sdkmanager --list [options] \ [--channel=channel_id] // Channels: 0 (stable), 1 (beta), 2 (dev), or 3 (canary) Use the channel option to include a package from a channel up to and including channel_id. For example, specify the canary channel to list packages from all channels. Install packages: sdkmanager packages [options] The packages argument is an SDK-style path, wrapped in quotes (for example, "build-tools;25.0.0" or "platforms;android-25"). You can pass multiple package paths, separated with a space, but they must each be wrapped in their own set of quotes.

示例用法(在我的Mac上):

alex@mbpro:~/sdk/tools/bin$ ls ../../build-tools/  
25.0.0/   
alex@mbpro:~/sdk/tools/bin$ ./sdkmanager "build-tools;25.0.2"  
done   
alex@mbpro:~/sdk/tools/bin$ ls ../../build-tools/  
25.0.0/ 25.0.2/

您还可以指定各种选项,例如强制所有连接使用HTTP(——no_https),或者为了使用代理服务器(——proxy_host=address和——proxy_port=port)。

要检查可用选项,使用——help标志。在我的机器(Mac)上,输出如下:

alex@mbpro:~/sdk/tools/bin$ ./sdkmanager --help
Usage: 
  sdkmanager [--uninstall] [<common args>] \
    [--package_file <package-file>] [<packages>...]
  sdkmanager --update [<common args>]
  sdkmanager --list [<common args>]

In its first form, installs, or uninstalls, or updates packages.
    <package> is a sdk-style path (e.g. "build-tools;23.0.0" or 
             "platforms;android-23").
    <package-file> is a text file where each line is a sdk-style path
                   of a package to install or uninstall.
    Multiple --package_file arguments may be specified in combination
     with explicit paths.
In its second form (with --update), currently installed packages are
    updated to the latest version.
In its third form, all installed and available packages are printed out.

Common Arguments:
    --sdk_root=<sdkRootPath>: Use the specified SDK root instead of the SDK containing this tool
    --channel=<channelId>: Include packages in channels up to <channelId>.
                           Common channels are:
                           0 (Stable), 1 (Beta), 2 (Dev), and 3 (Canary).

    --include_obsolete: With --list, show obsolete packages in the
                        package listing. With --update, update obsolete
                        packages as well as non-obsolete.
    --no_https: Force all connections to use http rather than https.
    --proxy=<http | socks>: Connect via a proxy of the given type.
    --proxy_host=<IP or DNS address>: IP or DNS address of the proxy to use.
    --proxy_port=<port #>: Proxy port to connect to.

* If the env var REPO_OS_OVERRIDE is set to "windows",
  "macosx", or "linux", packages will be downloaded for that OS.

我就遇到了这个问题,所以我最终通过读取和解析可用工具列表来编写了一行bash dirty解决方案:

 tools/android update sdk -u -t $(android list sdk | grep 'Android SDK Build-tools' | sed 's/ *\([0-9]\+\)\-.*/\1/')