现在我必须下载并安装Android SDK和AVD Manager,然后通过UI安装API和工具.有没有办法让这个过程自动化?

推荐答案

UPDATE

最新版本引入了sdkmanager,这是一个命令行工具,允许您查看、安装、更新和卸载Android SDK的软件包.

sdkmanager工具在Android SDK工具包(25.2.3 and higher)中提供,位于android_sdk/工具s/bin/中.

  sdkmanager [--uninstall] [<common args>] [--package_file <file>] [<packages>...]
  sdkmanager --update [<common args>]
  sdkmanager --list [<common args>]
  sdkmanager --licenses [<common args>]

In its first form, installs, or uninstalls, or updates packages.
    By default, the listed packages are installed or (if already installed)
    updated to the latest version.

    --uninstall: uninstalled listed packages.

    <package> is a sdk-style path (e.g. "build-工具s;23.0.0" or
             "站台s;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), all installed packages are
    updated to the latest version.

In its third form, all installed and available packages are printed
    out.

In its fourth form (with --licenses), show and offer the option to
     accept licenses for all available packages that have not already been
     accepted.

Common Arguments:
    --sdk_root=<sdkRootPath>: Use the specified SDK root instead of the SDK
                              containing this 工具

    --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.

因此,要更新包,请运行

sdkmanager --update

要接受许可证,

yes | sdkmanager --licenses

OLD ANSWER

(Please note: The 100 command is deprecated!)

你离自动化越近可能是:

android update sdk --no-ui

android提供以下自动更新选项:

Action "update sdk":
  Updates the SDK by suggesting new 站台s to install if available.
Options:
  -f --force    Forces replacement of a package or its parts, even if something has been modified
  -u --no-ui    Updates from command-line (does not display the GUI)
  -o --obsolete Installs obsolete packages
  -t --filter   A filter that limits the update to the specified types of packages in the form of
                a comma-separated list of [站台, 工具, 站台-工具, 单据, 样本, 额外的]
  -s --no-https Uses HTTP instead of HTTPS (the default) for downloads
  -n --dry-mode Simulates the update but does not download or install anything

如果要列出可用于安装的软件包,可以使用

android list sdk

例如,您将获得一个有序的包列表

Packages available for installation or update: 9
   1- ARM EABI v7a System Image, Android API 15, revision 2
   2- Intel x86 Atom System Image, Android API 15, revision 1
   3- Android Support, revision 8
   4- Google AdMob Ads SDK, revision 6
   5- Google Analytics SDK, revision 2
   6- Google Play APK Expansion Library, revision 1
   7- Google Play Billing Library, revision 2
   8- Google Play Licensing Library, revision 2
   9- Google Web Driver, revision 2

此外,如果使用--filter选项,还可以将更新限制为仅更新所需的组件

android update sdk --filter <component> --no-ui

其中,组件是以下一项或多项

  • android list sdk返回的数字(即1,也称为package index)
  • 附加组件
  • 单据
  • 额外的
  • 站台
  • 站台-工具
  • 样本
  • 来源
  • 系统映像
  • 工具

或者可以是一个或多个特定标识符.例如,如果您只想下载一组特定的软件包,您可以这样做:

android update sdk -u --filter 站台-工具s,android-16,额外的-android-support

您将只获得平台工具、API级别16和支持包JAR文件.如果您只构建一台构建机器,并且需要为下载所有您永远不会用到的额外内容付费,那么这将非常方便.

要查看您可以使用的可用选项--例如Help

android --help list sdk

       Usage:
       android [global options] list sdk [action options]
       Global options:
  -h --help       : Help on a specific command.
  -v --verbose    : Verbose mode, shows errors, warnings and all messages.
     --clear-cache: Clear the SDK Manager repository manifest cache.
  -s --silent     : Silent mode, shows errors only.

                   Action "list sdk":
  Lists remote SDK repository.
Options:
  -o --obsolete  : Deprecated. Please use --all instead.
  -a --all       : Lists all available packages (including obsolete and
                   installed ones)
     --proxy-host: HTTP/HTTPS proxy host (overrides settings if defined)
     --proxy-port: HTTP/HTTPS proxy port (overrides settings if defined)
  -s --no-https  : Uses HTTP instead of HTTPS (the default) for downloads.
  -e --extended  : Displays extended details on each package
  -u --no-ui     : Displays list result on console (no GUI) [Default: true]

Android相关问答推荐

为什么柱子的高度不都一样?

无法加载类';com.android.build.api.extension.AndroidComponentsExtension';

为什么它显示我的空白屏幕?

为什么Kotlin允许将非空值类型化为可空类型,但又将其视为非空值?

jetpackcompose-如何对解析后的复杂对象进行状态提升?

Kotlin - 在继续之前如何等待这个协程完成?

使用不同的gradle文件导入外部库

Spinner - onItemLongClick 从未执行

尽管我在onCreate()期间已经初始化,但仍出现未初始化的late init变量错误

将 CircularProgressIndicator 添加到按钮而不增加其高度

在 Jetpack Compose 中对齐行项目

为卡片的上半部分添加一个边框,用圆角半径组合

AttributionSource 需要 android.permission.BLUETOOTH_SCAN 权限的问题

如何在 Jetpack Compose 中添加多个标签

为什么我不能直接记住 mutableStateOf 可组合函数?

为什么官方文档用大写字母表示val变量?

Jetpack 使用 Canvas 组成半圆

使 Compose LazyColumn 的最后一项填满屏幕的其余部分

在jetpack compose中看不到圆角

如何在 Kotlin 中使用反向绑定适配器将小写文本转换为大写?