使用命令行+代理更新Android SDK


在無桌面的Linux上面安裝Jenkins,要配置成Andorid 的持續集成環境Jenkins持續集成Android項目,需要在無桌面的Linux(ubuntu,centos)上安裝Android SDK,
相對來說獲取android-sdk-linux的安裝包比較容易。

wget http://dl.google.com/android/android-sdk_r23.0.2-linux.tgz

這個包有時候在下不需要翻牆也可以成功下載,需要翻牆的話也可以在別的機器上面下載之后復制過來。
直接在系統上面解壓就可以,如果需要更新platformplatform-tool就麻煩了。
這里會遇到兩個問題:

1.一般更新Andorid SDK都是使用SDK Manager直接更新
2.更新Andorid,一個大家都知道的問題dl-ssl.google.com/android無法使用。

Android SDK 命令

到Andorid的安裝目錄,運行命令:

android -h

 Usage:
       android [global options] action [action options]
       Global options:
  -s --silent : Silent mode, shows errors only. -v --verbose : Verbose mode, shows errors, warnings and all messages. --clear-cache: Clear the SDK Manager repository manifest cache. -h --help : Help on a specific command. Valid actions are composed of a verb and an optional direct object: - sdk : Displays the SDK Manager window. - avd : Displays the AVD Manager window. - list : Lists existing targets or virtual devices. - list avd : Lists existing Android Virtual Devices. - list target : Lists existing targets. - list device : Lists existing devices. - list sdk : Lists remote SDK repository. - create avd : Creates a new Android Virtual Device. - move avd : Moves or renames an Android Virtual Device. - delete avd : Deletes an Android Virtual Device. - update avd : Updates an Android Virtual Device to match the folders of a new SDK. - create project : Creates a new Android project. - update project : Updates an Android project (must already have an AndroidManifest.xml). - create test-project : Creates a new Android project for a test package. - update test-project : Updates the Android project for a test package (must already have an AndroidManifest.xml). - create lib-project : Creates a new Android library project. - update lib-project : Updates an Android library project (must already have an AndroidManifest.xml). - create uitest-project: Creates a new UI test project. - update adb : Updates adb to support the USB devices declared in the SDK add-ons. - update sdk : Updates the SDK by suggesting new platforms to install if available.

可以看到這里有update sdk,update adb的升級命令。
更新Android SDK我們主要用到兩個命令:

android list sdk

從服務器上獲取到所有的Android的可用SDK.

android update sdk

更新SDK,--filter參數可以用來選擇要更新的SDK,一般情況下我們不會更新全部的SDK。也可以使用android update sdk --no-ui --all --force強制更新所有的SDK到電腦上。

使用代理更新

運行命令android list sdk 
一般情況下都會卡在:

Fetching https://dl.google.com/android/repository/addons_list-2.xml

因為大家都知道的原因google的服務無法使用。
還好android的命令提供了兩個代理參數:--proxy-host設置代理的host地址,--proxy-port設置代理的端口。
國內的Android代理鏡像服務器:

http://mirrors.neusoft.edu.cn 端口:80 http://ubuntu.buct.edu.cn/ 端口:80 http://ubuntu.buct.cn/ 端口:80 http://sdk.gdgshanghai.com 端口:8000 IPv6: http://ubuntu.buct6.edu.cn/ 端口:80 騰訊鏡像: http://android-mirror.bugly.qq.com 端口:8080 

使用代理查看SDK列表:

android list sdk --extended --proxy-host android-mirror.bugly.qq.com --proxy-port 8080 -s

 id: 1 or "doc-23" Type: Doc Desc: Documentation for Android SDK, API 23, revision 1 ---------- id: 2 or "android-21" Type: Platform Desc: Android SDK Platform 5.0.1 Revision 2 ..... id: 20 or "sample-8" Type: Sample Desc: Android SDK Samples for Android API 8, revision 1 ---------- ..... ---------- id: 31 or "extra-android-gapid" Type: Extra Desc: GPU Debugging tools, revision 1.0.3 By Android Tools that support GPU debugging and profiling within an IDE. Install path: extras/android/gapid ---------- id: 32 or "extra-android-m2repository" Type: Extra Desc: Local Maven repository for Support Libraries, revision 28 By Android Install path: extras/android/m2repository ---------- ......

使用代理更新指定SDK:

android update sdk --no-ui --filter 2 --proxy-host android-mirror.bugly.qq.com --proxy-port 8080 -s

安裝 id: 2 or "android-21"Android 21 的SDK。
安裝的時候提示接受license:

Do you accept the license 'android-sdk-preview-license-52d11cd2' [y/n]:

選擇y同意之后繼續安裝。
等待安裝成功。
使用國內的鏡像服務器安裝,服務穩定,下載速度快,不需要翻牆。
注:其中id為32是extra-android-m2repository,android的Support Libraries

錯誤

 Cannot run program "/var/lib/jenkins/tools/android-sdk/build-tools/23.0.1/aapt": error=2, No such file or directory at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048) at com.android.builder.png.AaptProcess$Builder.start(AaptProcess.java:163) at com.android.builder.png.QueuedCruncher$1.creation(QueuedCruncher.java:106) at com.android.builder.tasks.WorkQueue.run(WorkQueue.java:203) at java.lang.Thread.run(Thread.java:745) Caused by: java.io.IOException: error=2, No such file or directory at java.lang.UNIXProcess.forkAndExec(Native Method) at java.lang.UNIXProcess.<init>(UNIXProcess.java:248) at java.lang.ProcessImpl.start(ProcessImpl.java:134) at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029) ... 4 more Thread(png-cruncher_2) has a null payload

因為aapt是32的位,不能在64位的系統上面運行,需要安裝32位的支持。CentOS:

sudo yum install libz.so.1

Ubuntu:

sudo yum apt-get install lib32z1


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM