有没有办法自动安装android sdk?

don*_*gcn 203 android android-virtual-device android-sdk-tools

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

Die*_*ano 387

你越接近自动化可能是:

  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.
Run Code Online (Sandbox Code Playgroud)

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

$ sdkmanager --update
Run Code Online (Sandbox Code Playgroud)

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

$ yes | sdkmanager --licenses
Run Code Online (Sandbox Code Playgroud)

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

$ android update sdk --no-ui
Run Code Online (Sandbox Code Playgroud)

此外,如果使用该sdkmanager选项,则只能将更新限制为所需的组件

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
Run Code Online (Sandbox Code Playgroud)

组件是一个或多个

  • 返回的数字sdkmanager(即1,也称为包索引)
  • 添加在
  • DOC
  • 额外
  • 平台
  • 平台工具
  • 样品
  • 资源
  • 系统映像
  • 工具

或者可以是一个或多个特定标识符.例如,如果您只想下载一小组特定软件包,则可以执行以下操作:

$ android list sdk
Run Code Online (Sandbox Code Playgroud)

你将获得平台工具,api 16级和支持包jar.如果你只是在构建一台构建机器并且需要付费下载所有你永远不会使用的额外内容,这真的很方便.

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

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
Run Code Online (Sandbox Code Playgroud)

UPDATE

最新版本推出android_sdk/tools/bin/了一个命令行工具,允许您查看,安装,更新和卸载Android SDK的软件包.

--filter工具在Android SDK工具包(25.2.3及更高版本)中提供,位于android list sdk.

$ android update sdk --filter <component> --no-ui
Run Code Online (Sandbox Code Playgroud)

所以,要更新包运行

$ android update sdk -u --filter platform-tools,android-16,extra-android-support
Run Code Online (Sandbox Code Playgroud)

接受许可证

$ 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]
Run Code Online (Sandbox Code Playgroud)

  • 要自动接受许可证,下一版本将添加`--accept-license`标志.与此同时,你可以"回应"y"| android update sdk --no - ui` (32认同)
  • 使用捆绑的android.bat (3认同)
  • 我没有看到Windows SDK的"android.exe" - 如何在Windows上自动执行SDK安装和配置? (2认同)
  • @Snicolas我写了一个makefile,使用"expect"来自动接受许可协议.它在github上(https://github.com/ken-noland/android-autoget-makefile) (2认同)

dan*_*anb 50

这对我不起作用......

echo "y" | android ....
Run Code Online (Sandbox Code Playgroud)

所以我最终到了这里:

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
}
'
Run Code Online (Sandbox Code Playgroud)

  • 感谢简单的期望脚本,这是有效的,而是不是. (4认同)
  • 这看起来非常类似于此处提供的解决方案:http://stackoverflow.com/a/6674626/3063884 ...是否需要归属? (2认同)
  • @CJBS不.我得出了同样的结论.一旦你学会了"期待",这个结果几乎是你能想出来的唯一一个......但是感谢你提供归属感. (2认同)

Elm*_*mer 44

我使用它来安装和更新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
Run Code Online (Sandbox Code Playgroud)

  • 对我来说,还需要选项-a,以便找到过滤器中指定的所有包. (2认同)

nps*_*str 16

要使用'y'回答所有许可证,您可以在脚本中尝试:

(while :
do
  echo 'y'
  sleep 2
done) | android update sdk -u .....
Run Code Online (Sandbox Code Playgroud)

  • 我无法证实这是有效的.我得到一个错误听起来像"'yyyyyyyy'不是一个有效的答案",这就是为什么我回到解决方案与之间的睡眠. (10认同)

Tai*_* Le 5

对于仍在寻找下载所有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
Run Code Online (Sandbox Code Playgroud)

你也可以在我的Github回购中看到它

好处:

  • 不依赖expect.
  • 无头.

缺点:

  • 您仍然需要手动安装基本SDK,并将其放入android您的路径中.
  • 脚本仅适用于unix.


归档时间:

查看次数:

66552 次

最近记录:

6 年,2 月 前