现在我要下载并安装Android SDK和AVD管理器,然后通过UI安装api、工具。有没有办法使这个过程自动化?
当前回答
更新
最新版本引入了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
哪个组件是一个或多个
android列表SDK返回的数字(即1,也称为包索引) 附加组件 医生 额外的 平台 platform-tool 样本 源 系统映像 工具
或可以是一个或多个特定的标识符。例如,如果你只想下载一小部分特定的软件包,你可以这样做:
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]
其他回答
我用这个在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 .....
这对我没用……
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
}
'
更新
最新版本引入了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
哪个组件是一个或多个
android列表SDK返回的数字(即1,也称为包索引) 附加组件 医生 额外的 平台 platform-tool 样本 源 系统映像 工具
或可以是一个或多个特定的标识符。例如,如果你只想下载一小部分特定的软件包,你可以这样做:
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]
要在Windows上自动化sdkmanager.bat——license提示符(假设您正在通过自动化安装构建基础设施)…不要运行它。不要浪费时间试图弄清楚如何将y插入其中。我试着;可怜的失败。
相反,自己运行一次,并注意它会生成文件到C:\android\android-sdk\licenses(在这里您正在运行C:\android\android-sdk\tools\bin\sdkmanager.bat -您的安装根可能不同)。
获取这些文件,并将它们放在您可以在自动设置脚本中获取它们的地方。就我个人而言,Ansible是我的毒药,所以
# 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"}
...
推荐文章
- 在android中从上下文获取活动
- 无法解析主机"<URL here>"没有与主机名关联的地址
- getActivity()在Fragment函数中返回null
- 按钮背景是透明的
- 在Mac OS X上哪里安装Android SDK ?
- 我如何获得图像缩放功能?
- 在Android应用程序中显示当前时间和日期
- BottomSheetDialogFragment的圆角
- 在应用程序启动时出现“无法获得BatchedBridge,请确保您的bundle被正确打包”的错误
- 我如何改变默认对话框按钮的文本颜色在安卓5
- 更改单选按钮的圆圈颜色
- 如何在android中复制一个文件?
- adb找不到我的设备/手机(MacOS X)
- 如何在新的材质主题中改变背面箭头的颜色?
- androidviewpager与底部点