android - 有没有办法自动化 Android SDK 安装?

标签 android android-sdk-tools avd

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

最佳答案

更新

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

sdkmanager 工具在 Android SDK 工具包(25.2.3 及更高版本)中提供,位于 android_sdk/tools/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-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), 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 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.

所以,更新包运行

sdkmanager --update

要接受许可,

yes | sdkmanager --licenses

旧答案

(请注意:android 命令已弃用!)

您可能离自动化越近:

android update sdk --no-ui

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

Action "update sdk":
  Updates the SDK by suggesting new platforms 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 [platform, tool, platform-tool, doc, sample, extra]
  -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,也称为包索引)
  • 插件
  • 文档
  • 额外的
  • 平台
  • 平台工具
  • 样本
  • 来源
  • 系统镜像
  • 工具

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

android update sdk -u --filter platform-tools,android-16,extra-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 - 有没有办法自动化 Android SDK 安装?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4681697/

相关文章:

android - 使用 Intent 启动媒体播放器

android - Android 基于跟踪和基于采样的方法分析之间的差异及其对报告的 CPU 时间的影响

Android Studio - panic : Could not open AVD

android - AVD 管理器 - API 级别 23 上的 "No system images installed for this target."

javascript - 以编程方式滑回上一页

java - Android:使用 YouTube API 时应用程序存在后退点击

android - gradle experimental ndk 仅构建目录的子集

将 avd 与系统镜像 > android 30 一起使用时,Android 模拟器电源关闭按钮不起作用

adb:在 Mac OS X Yosemite 上找不到命令(来自 platform-tools 目录中)

android - 如何在 Android 模拟器上禁用保存状态?