现在,我必须下载并安装Android SDK ABD 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 (IE 1, , 也被称为 软件包索引)
  • 添加在
  • Doc
  • 额外的
  • 平台
  • 平台工具
  • 样本
  • 资源
  • 系统图像
  • 工具

也可以是一个或多个特定的标识符。例如,如果您只想下载一小部分特定软件包,则可以这样做:

$ android update sdk -u --filter platform-tools,android-16,extra-android-support

您只会获得平台工具,API级别16并支持包装罐。如果您只构建构建机器,这真的很方便,并且必须为下载您从未使用过的所有额外内容付费。

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

$ 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]

其他提示

这对我不起作用...

echo "y" | android ....

所以我最终来到这里:

expect -c '
set timeout -1   ;
spawn sudo /opt/android-sdk/tools/android update sdk -u; 
expect { 
    "Do you accept the license" { exp_send "y\r" ; exp_continue }
    eof
}
'

我用它来安装和更新Travis-CI上的SDK

curl --location http://dl.google.com/android/android-sdk_r22.3-linux.tgz | tar -x -z -C $HOME
export ANDROID_HOME=$HOME/android-sdk-linux
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
( sleep 5 && while [ 1 ]; do sleep 1; echo y; done ) | android update sdk --no-ui --filter platform-tool,android-19,sysimg-19,build-tools-19.0.1

要用“ Y”回答所有许可,您可以在脚本中尝试一下:

(while :
do
  echo 'y'
  sleep 2
done) | android update sdk -u .....

对于仍在寻找下载所有Android软件包的方法的任何人,我都编写了一个脚本来完成此操作。它将下载 所有未观察的 软件包。

#!/binbash
# Install all non-obsolete android sdk packages.
# author: Tai Le Tien (letientai299 at gmail.com)

function install_sdk {
  android update sdk -u -s -a -t "$1"
}

function fetch_non_obsoled_package_indices {
  # Fetch the sdk list using non-https connections
  android list sdk -u -s -a |\
    # Filter obsoleted packages
    sed '/\(Obsolete\)/d' |\
    # Filter to take only the index number of package
    sed 's/^[ ]*\([0-9]*\).*/\1/' |\
    # Remove the empty lines
    sed -n 's/^[^ $]/\0/p'
}

for package_index in  $(fetch_non_obsoled_package_indices)
do
  echo "====================================================================="
  echo "Start to install package:  ${package_index}"
  echo "====================================================================="
  # Auto accept license
  echo -e "y" | install_sdk "${package_index}"
  echo
  echo
done

你也可以在我的 Github仓库

好:

  • 不依赖 expect.
  • 无头。

缺点:

  • 您仍然必须手动安装基本SDK,然后放置 android 进入你的路。
  • 脚本仅在UNIX上工作。

从...开始 Gradle的Android插件 版本2.2.0,缺少SDK组件 自动下载.

在较新的Android版本中(例如 25.2.5)我们应该使用 SDKMANAGER (而不是 android 命令)

安装软件包的示例:

android-sdk/tools/bin/sdkmanager "extras;android;m2repository"

命令获取所有可用软件包的列表:

 android-sdk/tools/bin/sdkmanager --verbose --list

此网页 列表下载SDK-Tools的链接:

这是开源存储库的链接 Docker-android 可以在Docker图像中安装Android。

您可能还会找到答案 这个问题:自动接受所有SDK许可证 有用。

我整理了一个Ruby脚本,该脚本下载并安装SDK而不提示可能会有所帮助。https://github.com/ayvazj/andenv

还有另一个仅需要下载的脚本,nond- {oploce,source,emulator-image,doc} packages:

#!/bin/bash
set -e

# cd into where tools/android can be found
if [[ -d "$ANDROID_HOME" ]]; then
  cd "$ANDROID_HOME"
elif [[ -x "$(dirname "$0")/tools/android" ]]; then
  cd "$(dirname "$0")"
else
  echo "FAILED: Cannot find ANDROID_HOME/tools/android"
  exit 1
fi

android () {
  "$(dirname $0)/tools/android" "$@"
}

needed_packages () {
  android list sdk -u -s -e         \
    | grep '^id:'                   \
    | cut -d'"' -f2                 \
    | grep -v 'source'              \
    | grep -v 'sys-img'             \
    | grep -v 'doc'                 \
    | paste -d, -s -
}

main () {
  (while : ; do
  echo 'y'
  sleep 1
  done) | android update sdk -u -s -a -t "$(needed_packages)"
}

main

某些部分是从该线程中的其他答案中获取的。

对于新手Android开发人员而言,但是经验丰富的Java开发人员,即使您经历了上述所有噩梦,也很难知道哪些依赖性。我的同事建议我使用Android Studio(基于Intellij :-) 具体来说 因为上述噩梦。我遵循他的建议。但是我不接受安装的默认值,而是尝试将其安装在我的软件驱动器中。原来是一场噩梦。 SDK对话似乎悬而未决,根本不直观。这就是为什么我最终来到这里的原因。阅读了上述内容后,我给了Studio又尝试了一下,这次接受了插件的所有默认值。嘿,Presto ...它在几个对话中照顾了所有SDK依赖项(我猜是核心的依赖项),而不会提示CTL-SHIFT-S和SKD。因此,我会推荐给新手。这里下载布丁的证明:enter image description here

我下载并安装了Sudio的版本:enter image description hereWindows的版本:enter image description here在这里做好准备之后:enter image description here

衷心希望它对您有用!

自动化 sdkmanager.bat --licenses 在Windows上提示(例如,您是通过自动化安装以进行构建基础架构)...请勿运行它。不要浪费时间试图弄清楚如何管道 y 进去。我试过了;失败。

相反 - 一次运行一次,请注意,它将文件生成 c:\android\android-sdk\licenses (在哪里运行 c:\android\android-sdk\tools\bin\sdkmanager.bat - 您的安装根可能会有所不同)。

获取这些文件,然后将它们放在可以从自动设置脚本中获取的地方。就我个人而言是我的毒药,所以:

# Note to future-us:
# These are magical files generated by running `c:/android/android-sdk/tools/bin/sdkmanager.bat --licenses`
# This, delightfully, is interactive, and wants to _actually_ read the keyboard buffer.
# That's reputedly possible via SendKeys. I elected to not try that.
# So, instead:
# 1) remote to an instance like a cave-dweller
# 2) run `c:/android/android-sdk/tools/bin/sdkmanager.bat --licenses` in a prompt.
# 3) _actually type_ `y` however many godforsaken times you need to.
# 4) meticulously harvest `c:/android/android-sdk/licenses/*` to this task.
#    (you don't need the newline that they thoughtfully put before the hash in each file).
- name: set up android licenses by hand
  win_lineinfile:
    path: c:/android/android-sdk/licenses/{{ item.name }}
    line: "{{ item.line }}"
    create: true
  with_items:
    - {name: "android-googletv-license", line: "SOME HASH"}
    - {name: "android-sdk-license", line: "SOME OTHER HASH"}
    ...
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top