Ubuntu下全命令行安装Android SDK

时间:2021-04-19 21:30:21

为了在AWS云服务器上实现自动化打包Android APP的APK包,我需要远程命令行环境下安装Android SDK,当然还要用代理或者*,这里简单整理一下过程:

首先,由于墙的原因,Android SDK基本无法直接下,必须使用代理或者国内镜像之类,这里推荐使用上海交大的,参数:

--proxy-host sdk.gdgshanghai.com --proxy-port 8000

以下是具体的安装步骤

1)安装JDK,建议不要使用OpenJDK,使用Oracle的官方版本最佳

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer
sudo apt-get install oracle-java8-set-default
sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/java-8-oracle/bin/java 300
sudo update-alternatives --config java 
sudo vi /etc/environment (添加一行:JAVA_HOME=/usr/lib/jvm/java-8-oracle)

2)安装Android SDK (两种方式,可以直接安装android-studio,不过我用的是亚马逊云的T2.micro主机硬盘很小,为节省空间还是只安装android sdk)

sudo apt-get install lib32z1 lib32ncurses5 lib32stdc++6

wget http://dl.gmirror.org/android/android-sdk_r24.4.1-linux.tgz (从国内镜像下载)
tar -zxvf android-sdk_r24.4.1-linux.tgz

sudo mv ./android-sdk-linux /opt/

3)设置环境变量

echo 'export ANDROID_HOME="/opt/android-sdk-linux"' >> ~/.bashrc
echo 'export PATH="$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools"' >> ~/.bashrc
echo 'export JAVA_CMD="/usr/lib/jvm/java-8-oracle/bin/java"' >> ~/.bashrc

4)通过国内镜像下载最新SDK工具

cd /opt/android-sdk-linux/tools

./android -v update sdk -u -s --proxy-host sdk.gdgshanghai.com --proxy-port 8000

(其中,-u参数为不使用GUI方式,同--no-ui参数一致)

5)列出其他安装包

./android -v list sdk --proxy-host sdk.gdgshanghai.com --proxy-port 8000

此命令会列出可更新或者安装的包(非全部)

例如:

Packages available for installation or update: 3
1- SDK Platform Android 2.3.3, API 10, revision 2
2- SDK Platform Android 2.2, API 8, revision 3
3- Samples for SDK API 23, revision 2

根据你需要的编号,输入以下命令进行安装,例如,需要安装3- Samples for SDK API 23, revision 2:

./android update sdk -u --filter 3 --proxy-host sdk.gdgshanghai.com --proxy-port 8000

6)列出所有安装包(-a参数)

./android -v list sdk -a --proxy-host sdk.gdgshanghai.com --proxy-port 8000

此命令会列出所有安装包

例如:

Packages available for installation or update: 160
1- Android SDK Tools, revision 24.4.1
2- Android SDK Tools, revision 25.0.1 rc2
3- Android SDK Platform-tools, revision 23.1
4- Android SDK Build-tools, revision 23.0.2
5- Android SDK Build-tools, revision 23.0.1
6- Android SDK Build-tools, revision 23 (Obsolete)
7- Android SDK Build-tools, revision 22.0.1
8- Android SDK Build-tools, revision 22 (Obsolete)
9- Android SDK Build-tools, revision 21.1.2
10- Android SDK Build-tools, revision 21.1.1 (Obsolete)
11- Android SDK Build-tools, revision 21.1 (Obsolete)
12- Android SDK Build-tools, revision 21.0.2 (Obsolete)
13- Android SDK Build-tools, revision 21.0.1 (Obsolete)
14- Android SDK Build-tools, revision 21 (Obsolete)
15- Android SDK Build-tools, revision 20
16- Android SDK Build-tools, revision 19.1
17- Android SDK Build-tools, revision 19.0.3 (Obsolete)
18- Android SDK Build-tools, revision 19.0.2 (Obsolete)
19- Android SDK Build-tools, revision 19.0.1 (Obsolete)
20- Android SDK Build-tools, revision 19 (Obsolete)
21- Android SDK Build-tools, revision 18.1.1 (Obsolete)
22- Android SDK Build-tools, revision 18.1 (Obsolete)
23- Android SDK Build-tools, revision 18.0.1 (Obsolete)
24- Android SDK Build-tools, revision 17 (Obsolete)
25- Documentation for Android SDK, API 23, revision 1
26- SDK Platform Android 6.0, API 23, revision 2
27- SDK Platform Android 5.1.1, API 22, revision 2
28- SDK Platform Android 5.0.1, API 21, revision 2
29- SDK Platform Android 4.4W.2, API 20, revision 2
30- SDK Platform Android 4.4.2, API 19, revision 4
31- SDK Platform Android 4.3.1, API 18, revision 3
32- SDK Platform Android 4.2.2, API 17, revision 3
33- SDK Platform Android 4.1.2, API 16, revision 5
34- SDK Platform Android 4.0.3, API 15, revision 5
35- SDK Platform Android 4.0, API 14, revision 4 (Obsolete)
36- SDK Platform Android 3.2, API 13, revision 1 (Obsolete)
37- SDK Platform Android 3.1, API 12, revision 3 (Obsolete)
38- SDK Platform Android 3.0, API 11, revision 2 (Obsolete)
39- SDK Platform Android 2.3.3, API 10, revision 2
40- SDK Platform Android 2.3.1, API 9, revision 2 (Obsolete)
41- SDK Platform Android 2.2, API 8, revision 3
42- SDK Platform Android 2.1, API 7, revision 3 (Obsolete)
43- SDK Platform Android 2.0.1, API 6, revision 1 (Obsolete)
44- SDK Platform Android 2.0, API 5, revision 1 (Obsolete)
45- SDK Platform Android 1.6, API 4, revision 3 (Obsolete)
46- SDK Platform Android 1.5, API 3, revision 4 (Obsolete)
47- SDK Platform Android 1.1, API 2, revision 1 (Obsolete)
48- Samples for SDK API 23, revision 2
49- Samples for SDK API 22, revision 6
50- Samples for SDK API 21, revision 4
51- Samples for SDK API 20, revision 3
52- Samples for SDK API 19, revision 6
53- Samples for SDK API 18, revision 1
54- Samples for SDK API 17, revision 1
55- Samples for SDK API 16, revision 1
56- Samples for SDK API 15, revision 2
57- Samples for SDK API 14, revision 2 (Obsolete)
58- Samples for SDK API 13, revision 1 (Obsolete)
59- Samples for SDK API 12, revision 1 (Obsolete)
60- Samples for SDK API 11, revision 1 (Obsolete)
61- Samples for SDK API 10, revision 1
62- Samples for SDK API 9, revision 1 (Obsolete)
63- Samples for SDK API 8, revision 1
64- Samples for SDK API 7, revision 1 (Obsolete)
65- Android TV ARM EABI v7a System Image, Android API 23, revision 2
66- Android TV Intel x86 Atom System Image, Android API 23, revision 2
67- Android Wear ARM EABI v7a System Image, Android API 23, revision 1
68- Android Wear Intel x86 Atom System Image, Android API 23, revision 1
69- ARM EABI v7a System Image, Android API 23, revision 3
70- Intel x86 Atom_64 System Image, Android API 23, revision 7
71- Intel x86 Atom System Image, Android API 23, revision 7
72- Android TV ARM EABI v7a System Image, Android API 22, revision 1
73- Android TV Intel x86 Atom System Image, Android API 22, revision 1
74- Android Wear ARM EABI v7a System Image, Android API 22, revision 7
75- Android Wear Intel x86 Atom System Image, Android API 22, revision 7
76- ARM EABI v7a System Image, Android API 22, revision 1
77- Intel x86 Atom_64 System Image, Android API 22, revision 3
78- Intel x86 Atom System Image, Android API 22, revision 3
79- Android TV ARM EABI v7a System Image, Android API 21, revision 3
80- Android TV Intel x86 Atom System Image, Android API 21, revision 3
81- Android Wear ARM EABI v7a System Image, Android API 21, revision 3
82- Android Wear Intel x86 Atom System Image, Android API 21, revision 3
83- ARM EABI v7a System Image, Android API 21, revision 3
84- Intel x86 Atom_64 System Image, Android API 21, revision 3
85- Intel x86 Atom System Image, Android API 21, revision 3
86- Android Wear ARM EABI v7a System Image, Android API 20, revision 4
87- Android Wear Intel x86 Atom System Image, Android API 20, revision 4
88- ARM EABI v7a System Image, Android API 19, revision 3
89- Intel x86 Atom System Image, Android API 19, revision 3
90- ARM EABI v7a System Image, Android API 18, revision 3
91- Intel x86 Atom System Image, Android API 18, revision 2
92- ARM EABI v7a System Image, Android API 17, revision 3
93- Intel x86 Atom System Image, Android API 17, revision 2
94- MIPS System Image, Android API 17, revision 1
95- ARM EABI v7a System Image, Android API 16, revision 4
96- Intel x86 Atom System Image, Android API 16, revision 2
97- MIPS System Image, Android API 16, revision 4
98- ARM EABI v7a System Image, Android API 15, revision 3
99- Intel x86 Atom System Image, Android API 15, revision 2
100- MIPS System Image, Android API 15, revision 1
101- ARM EABI v7a System Image, Android API 14, revision 2 (Obsolete)
102- Intel x86 Atom System Image, Android API 10, revision 3
103- Google APIs, Android API 23, revision 1
104- Google APIs, Android API 22, revision 1
105- Google APIs, Android API 21, revision 1
106- Google APIs (x86 System Image), Android API 19, revision 18
107- Google APIs (ARM System Image), Android API 19, revision 18
108- Glass Development Kit Preview, Android API 19, revision 11
109- Google APIs, Android API 18, revision 4
110- Google APIs, Android API 17, revision 4
111- Google APIs, Android API 16, revision 4
112- Google APIs, Android API 15, revision 3
113- Google APIs, Android API 14, revision 2 (Obsolete)
114- Google APIs, Android API 13, revision 1 (Obsolete)
115- Google TV Addon, Android API 13, revision 1 (Obsolete)
116- Google APIs, Android API 12, revision 1 (Obsolete)
117- Google TV Addon, Android API 12, revision 2 (Obsolete)
118- Google APIs, Android API 11, revision 1 (Obsolete)
119- Google APIs, Android API 10, revision 2
120- Google APIs, Android API 9, revision 2 (Obsolete)
121- Google APIs, Android API 8, revision 2
122- Google APIs, Android API 7, revision 1 (Obsolete)
123- Google APIs, Android API 6, revision 1 (Obsolete)
124- Google APIs, Android API 5, revision 1 (Obsolete)
125- Google APIs, Android API 4, revision 2 (Obsolete)
126- Google APIs, Android API 3, revision 3 (Obsolete)
127- Google APIs ARM EABI v7a System Image, Google Inc. API 23, revision 7
128- Google APIs Intel x86 Atom_64 System Image, Google Inc. API 23, revision 11
129- Google APIs Intel x86 Atom System Image, Google Inc. API 23, revision 11
130- Google APIs ARM EABI v7a System Image, Google Inc. API 22, revision 1
131- Google APIs Intel x86 Atom_64 System Image, Google Inc. API 22, revision 3
132- Google APIs Intel x86 Atom System Image, Google Inc. API 22, revision 2
133- Google APIs ARM EABI v7a System Image, Google Inc. API 21, revision 10
134- Google APIs Intel x86 Atom_64 System Image, Google Inc. API 21, revision 10
135- Google APIs Intel x86 Atom System Image, Google Inc. API 21, revision 10
136- Sources for Android SDK, API 23, revision 1
137- Sources for Android SDK, API 22, revision 1
138- Sources for Android SDK, API 21, revision 1
139- Sources for Android SDK, API 20, revision 1
140- Sources for Android SDK, API 19, revision 2
141- Sources for Android SDK, API 18, revision 1
142- Sources for Android SDK, API 17, revision 1
143- Sources for Android SDK, API 16, revision 2
144- Sources for Android SDK, API 15, revision 2
145- Sources for Android SDK, API 14, revision 1 (Obsolete)
146- GPU Debugging tools, revision 1.0.3
147- Android Support Repository, revision 25
148- Android Support Library, revision 23.1.1
149- Google AdMob Ads SDK, revision 11 (Obsolete)
150- Google Analytics App Tracking SDK, revision 3 (Obsolete)
151- Android Auto Desktop Head Unit emulator, revision 1.1
152- Google Cloud Messaging for Android Library, revision 3 (Obsolete)
153- Google Play services for Froyo, revision 12 (Obsolete)
154- Google Play services, revision 29
155- Google Repository, revision 24
156- Google Play APK Expansion Library, revision 3
157- Google Play Billing Library, revision 5
158- Google Play Licensing Library, revision 2
159- Android Auto API Simulators, revision 1
160- Google Web Driver, revision 2

然后从这160个中选择你需要的包进行安装:

例如,从160个全列表中安装7- Android SDK Build-tools, revision 22.0.1

./android update sdk -u -a --filter 7 --proxy-host sdk.gdgshanghai.com --proxy-port 8000