最近將公司的項目部署了Jenkins
持續集成,遇到了幾個麻煩的點,其中之一就是將Android SDK
進行配置在遠程服務器(總結下來還是自己對Linux命令還不夠熟悉),特此記錄。
- 系統: Ubuntu Server 16.04.1 LTS 64位
- 前置:完成
JDK
的環境搭建
1.下載SDK
點擊進入下載網址 下載對應的 android-sdk_r24.4.1-linux.tgz
文件。
2.解壓下載的壓縮包
tar -zxvf android-sdk_r24.4.1-linux.tgz
3.安裝32位庫
Android SDK中的adb程序是32位的,Ubuntu x64系統需要安裝32位庫文件,用於兼容32位的程序:
sudo apt-get install -y libc6-i386 lib32stdc++6 lib32gcc1 lib32ncurses5 lib32z1

4.配置環境變量
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

通過 vim /etc/profile
查看 或 編輯 環境變量的配置(或者直接通過export
命令查看):

5.下載最新SDK工具
進入tools
目錄下,輸入./android -v list sdk
命令查看可下載更新的SDK
列表:


官方提供了一些參數供開發者選擇性更新:
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 update sdk --filter <component> --no-ui
命令進行 組件 的過濾性篩選。
筆者選擇了簡單粗暴,直接通過android update sdk --no-ui
命令下載所有版本的sdk。
6.將sdk配置到Jenkins
打開Jenkins
的 系統配置界面,將對應的SDK根目錄配置給環境變量:

7.構建錯誤處理
缺少License
錯誤日志:
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文件傳到遠程服務器中:

對應版本的SDK Build-Tools不存在
錯誤日志: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)

解決方案,更新對應的BuildTools版本:
查看所有版本列表:
./android list sdk -a

更新對應的27.0.3版本:
android update sdk -u -t 7 -a
