最近將公司的項(xiàng)目部署了Jenkins
持續(xù)集成席怪,遇到了幾個(gè)麻煩的點(diǎn),其中之一就是將Android SDK
進(jìn)行配置在遠(yuǎn)程服務(wù)器(總結(jié)下來(lái)還是自己對(duì)Linux命令還不夠熟悉)耿导,特此記錄。
- 系統(tǒng): Ubuntu Server 16.04.1 LTS 64位
- 前置:完成
JDK
的環(huán)境搭建
1.下載SDK
點(diǎn)擊進(jìn)入下載網(wǎng)址 下載對(duì)應(yīng)的 android-sdk_r24.4.1-linux.tgz
文件晚树。
2.解壓下載的壓縮包
tar -zxvf android-sdk_r24.4.1-linux.tgz
3.安裝32位庫(kù)
Android SDK中的adb程序是32位的宝鼓,Ubuntu x64系統(tǒng)需要安裝32位庫(kù)文件沥寥,用于兼容32位的程序:
sudo apt-get install -y libc6-i386 lib32stdc++6 lib32gcc1 lib32ncurses5 lib32z1
4.配置環(huán)境變量
export ANDROID_SDK_HOME=/home/XXX/android/sdk/android-sdk-linux
export PATH=$PATH:${ANDROID_SDK_HOME}/tools
export PATH=$PATH:${ANDROID_SDK_HOME}/platform-tools
通過(guò) vim /etc/profile
查看 或 編輯 環(huán)境變量的配置(或者直接通過(guò)export
命令查看):
5.下載最新SDK工具
進(jìn)入tools
目錄下鳄厌,輸入./android -v list sdk
命令查看可下載更新的SDK
列表:
官方提供了一些參數(shù)供開(kāi)發(fā)者選擇性更新:
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
上述參數(shù)通過(guò)android update sdk --filter <component> --no-ui
命令進(jìn)行 組件 的過(guò)濾性篩選。
筆者選擇了簡(jiǎn)單粗暴廊营,直接通過(guò)android update sdk --no-ui
命令下載所有版本的sdk歪泳。
6.將sdk配置到Jenkins
打開(kāi)Jenkins
的 系統(tǒng)配置界面露筒,將對(duì)應(yīng)的SDK根目錄配置給環(huán)境變量:
7.構(gòu)建錯(cuò)誤處理
缺少License
錯(cuò)誤日志:
What went wrong:
A problem occurred configuring project ':xxx'.
Failed to install the following Android SDK packages as some licences have not been accepted.
build-tools;27.0.3 Android SDK Build-Tools 27.0.3
To build this project, accept the SDK license agreements and install the missing components using the Android Studio SDK Manager.
解決方案:
將本地sdk目錄下的licenses
文件夾中的License文件傳到遠(yuǎn)程服務(wù)器中:
對(duì)應(yīng)版本的SDK Build-Tools不存在
錯(cuò)誤日志:Failed to install the following SDK components:
build-tools;27.0.3 Android SDK Build-Tools 27.0.3
The SDK directory is not writable (/home/sdk/android-sdk-linux)
解決方案呐伞,更新對(duì)應(yīng)的BuildTools版本:
查看所有版本列表:
./android list sdk -a
更新對(duì)應(yīng)的27.0.3版本:
android update sdk -u -t 7 -a