如何纯命令行进行andorid SDK的更新及自动确认license的方法

/*****************************
* Author : Samson
* Date : 09/07/2015
* Test platform:
* gcc 4.8.4
* GNU bash, 4.3.30
* Debian GNU/Linux 8
* ***************************/


大部分时候,都是会使用andorid图形界面来完成SDK的配置及更新,但对于要完成自动化更新的需求来说,图形界面的并不是好的选择,那么如何纯命令行式地进行呢?

使用命令./android list sdk --all 可以得到远程服务器提供的所有的SDK、playservice、support等包的序号,记住想要更新的SDK序号,再使用命令android update sdk -u -a -t SDK_num1,SDK_num2,SDK_num3,SDK_num4……即可。

以上的步骤并不能够安装成功,那是因为要进行Do you accept the license的确认才会被安装,而命令行中并没有对此情况进行处理,那么就要进行命令行的交互式的操作了,使用expect命令完成此项功能。

$./android list sdk --all
Packages available for installation or update: 108
   1- Android SDK Tools, revision 24.3.4
   2- Android SDK Platform-tools, revision 23
   3- Android SDK Build-tools, revision 23
   4- Android SDK Build-tools, revision 22.0.1
   5- Android SDK Build-tools, revision 22 (Obsolete)
   6- Android SDK Build-tools, revision 21.1.2
   7- Android SDK Build-tools, revision 21.1.1 (Obsolete)
   8- Android SDK Build-tools, revision 21.1 (Obsolete)
   9- Android SDK Build-tools, revision 21.0.2 (Obsolete)
  10- Android SDK Build-tools, revision 21.0.1 (Obsolete)
  11- Android SDK Build-tools, revision 21 (Obsolete)
  12- Android SDK Build-tools, revision 20
  13- Android SDK Build-tools, revision 19.1
  14- Android SDK Build-tools, revision 19.0.3 (Obsolete)
  15- Android SDK Build-tools, revision 19.0.2 (Obsolete)
  16- Android SDK Build-tools, revision 19.0.1 (Obsolete)
  17- Android SDK Build-tools, revision 19 (Obsolete)
  18- Android SDK Build-tools, revision 18.1.1 (Obsolete)
  19- Android SDK Build-tools, revision 18.1 (Obsolete)
  20- Android SDK Build-tools, revision 18.0.1 (Obsolete)
  21- Android SDK Build-tools, revision 17 (Obsolete)
  22- Documentation for Android SDK, API 23, revision 1
  23- Documentation for Android SDK, API 22, revision 1
  24- SDK Platform Android 6.0, API 23, revision 1
  25- SDK Platform Android 5.1.1, API 22, revision 2
  26- SDK Platform Android 5.0.1, API 21, revision 2
  27- SDK Platform Android 4.4W.2, API 20, revision 2
  28- SDK Platform Android 4.4.2, API 19, revision 4
  29- SDK Platform Android 4.3.1, API 18, revision 3
  30- SDK Platform Android 4.2.2, API 17, revision 3
  31- SDK Platform Android 4.1.2, API 16, revision 5
  32- SDK Platform Android 4.0.3, API 15, revision 5
  33- SDK Platform Android 4.0, API 14, revision 4 (Obsolete)
  34- SDK Platform Android 3.2, API 13, revision 1 (Obsolete)
  35- SDK Platform Android 3.1, API 12, revision 3 (Obsolete)
  36- SDK Platform Android 3.0, API 11, revision 2 (Obsolete)
  37- SDK Platform Android 2.3.3, API 10, revision 2
  38- SDK Platform Android 2.3.1, API 9, revision 2 (Obsolete)
  39- SDK Platform Android 2.2, API 8, revision 3
  40- SDK Platform Android 2.1, API 7, revision 3 (Obsolete)
  41- SDK Platform Android 2.0.1, API 6, revision 1 (Obsolete)
  42- SDK Platform Android 2.0, API 5, revision 1 (Obsolete)
  43- SDK Platform Android 1.6, API 4, revision 3 (Obsolete)
  44- SDK Platform Android 1.5, API 3, revision 4 (Obsolete)
  45- SDK Platform Android 1.1, API 2, revision 1 (Obsolete)
  46- Samples for SDK API 23, revision 2
  47- Samples for SDK API 22, revision 6
  48- Samples for SDK API 21, revision 4
  49- Samples for SDK API 20, revision 3
  50- Samples for SDK API 19, revision 6
  51- Samples for SDK API 18, revision 1
  52- Samples for SDK API 17, revision 1
  53- Samples for SDK API 16, revision 1
  54- Samples for SDK API 15, revision 2
  55- Samples for SDK API 14, revision 2 (Obsolete)
  56- Samples for SDK API 13, revision 1 (Obsolete)
  57- Samples for SDK API 12, revision 1 (Obsolete)
  58- Samples for SDK API 11, revision 1 (Obsolete)
  59- Samples for SDK API 10, revision 1
  60- Samples for SDK API 9, revision 1 (Obsolete)
  61- Samples for SDK API 8, revision 1
  62- Samples for SDK API 7, revision 1 (Obsolete)
  63- Google APIs, Android API 23, revision 1
  64- Google APIs, Android API 22, revision 1
  65- Google APIs, Android API 21, revision 1
  66- Google APIs (ARM System Image), Android API 19, revision 15
  67- Google APIs, Android API 18, revision 4
  68- Google APIs, Android API 17, revision 4
  69- Google APIs, Android API 16, revision 4
  70- Google APIs, Android API 15, revision 3
  71- Google APIs, Android API 14, revision 2 (Obsolete)
  72- Google APIs, Android API 13, revision 1 (Obsolete)
  73- Google TV Addon, Android API 13, revision 1 (Obsolete)
  74- Google APIs, Android API 12, revision 1 (Obsolete)
  75- Google TV Addon, Android API 12, revision 2 (Obsolete)
  76- Google APIs, Android API 11, revision 1 (Obsolete)
  77- Google APIs, Android API 10, revision 2
  78- Google APIs, Android API 9, revision 2 (Obsolete)
  79- Google APIs, Android API 8, revision 2
  80- Google APIs, Android API 7, revision 1 (Obsolete)
  81- Google APIs, Android API 6, revision 1 (Obsolete)
  82- Google APIs, Android API 5, revision 1 (Obsolete)
  83- Google APIs, Android API 4, revision 2 (Obsolete)
  84- Google APIs, Android API 3, revision 3 (Obsolete)
  85- Sources for Android SDK, API 23, revision 1
  86- Sources for Android SDK, API 22, revision 1
  87- Sources for Android SDK, API 21, revision 1
  88- Sources for Android SDK, API 20, revision 1
  89- Sources for Android SDK, API 19, revision 2
  90- Sources for Android SDK, API 18, revision 1
  91- Sources for Android SDK, API 17, revision 1
  92- Sources for Android SDK, API 16, revision 2
  93- Sources for Android SDK, API 15, revision 2
  94- Sources for Android SDK, API 14, revision 1 (Obsolete)
  95- Android Support Repository, revision 17
  96- Android Support Library, revision 23
  97- Google AdMob Ads SDK, revision 11 (Obsolete)
  98- Google Analytics App Tracking SDK, revision 3 (Obsolete)
  99- Android Auto Desktop Head Unit emulator, revision 1
 100- Google Cloud Messaging for Android Library, revision 3 (Obsolete)
 101- Google Play services for Froyo, revision 12 (Obsolete)
 102- Google Play services, revision 26
 103- Google Repository, revision 21
 104- Google Play APK Expansion Library, revision 3
 105- Google Play Billing Library, revision 5
 106- Google Play Licensing Library, revision 2
 107- Android Auto API Simulators, revision 1
 108- Google Web Driver, revision 2
 
 针对以上的项选择安装如下序号的包:
 1,2,3,24,25,26,27,28,30,95,96,102,103,104,105,106,107
 
 自动进行license确认的脚本如下:
 #!/usr/bin/expect
set timeout -1
spawn /usr/local/android-sdk-linux/tools/android update sdk -u -a -t 1,2,3,24,25,26,27,28,30,95,96,102,103,104,105,106,107
expect {
    "Do you accept the license" { exp_send "y\r" ; exp_continue }
    eof
}

这样才真正的在纯命令行的环境下完成了android sdk的更新。
490

你可能感兴趣的:(如何纯命令行进行andorid SDK的更新及自动确认license的方法)