您想要的是能够在命令行中获得与 SDK Manager GUI 相同的功能。
发出此命令以从存储库中查询所有可用的包。该查询将返回左侧带有索引号的包。
[rgulia@xinu ~]$ android list sdk --all
Refresh Sources:
Fetching https://dl-ssl.google.com/android/repository/addons_list-2.xml
Validate XML
Parse XML
Fetched Add-ons List successfully
…
Validate XML: https://dl-ssl.google.com/android/repository/sys-img/x86/addon-x86.xml
Parse XML: https://dl-ssl.google.com/android/repository/sys-img/x86/addon-x86.xml
Packages available for installation or update: 138
1- Android SDK Tools, revision 24.1.2
2- Android SDK Platform-tools, revision 22
3- Android SDK Build-tools, revision 22.0.1
4- Android SDK Build-tools, revision 22 (Obsolete)
5- Android SDK Build-tools, revision 21.1.2
….
您可以使用 grep 命令来缩小搜索范围。例如:
[rgulia@xinu ~]$ android list sdk --all | grep -i tools | grep 21
5- Android SDK Build-tools, revision 21.1.2
6- Android SDK Build-tools, revision 21.1.1 (Obsolete)
7- Android SDK Build-tools, revision 21.1 (Obsolete)
8- Android SDK Build-tools, revision 21.0.2 (Obsolete)
9- Android SDK Build-tools, revision 21.0.1 (Obsolete)
10- Android SDK Build-tools, revision 21 (Obsolete)
最后,通过在此命令中提供其索引号来安装所需的包。
[rgulia@xinu ~]$ android update sdk -u -a -t 5
选项具有以下含义:
-u (--no-ui) # Headless mode
-a (--all) # Includes all packages, included the obsolete ones
-t (--filter) # in this example we have filtered by package index, i.e. 5