209

次に、AndroidSDKとAVDManagerをダウンロードしてインストールしてから、UIを介してAPIとツールをインストールする必要があります。このプロセスを自動化する方法はありますか?

4

11 に答える 11

395

アップデート

最新バージョンsdkmanagerでは、Android SDK のパッケージを表示、インストール、更新、およびアンインストールできるコマンド ライン ツールである が導入されています。

このsdkmanagerツールは、Android SDK Tools パッケージ ( 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

ここで、コンポーネントは次の 1 つまたは複数です。

  • によって返される数値android list sdk(つまり、 1package indexとも呼ばれます)
  • アドオン
  • 文書
  • 追加
  • プラットホーム
  • プラットフォームツール
  • サンプル
  • ソース
  • システム イメージ
  • 道具

または、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]
于 2011-01-13T16:10:38.267 に答える
46

これを使用して、 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
于 2014-02-20T14:03:51.360 に答える
0

{obsolete, source, emulator-image, doc} 以外の必要なパッケージのみをダウンロードするスクリプト:

#!/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

一部の部分は他の回答から取られています。

于 2016-06-19T07:51:51.563 に答える