前面的文章介绍了Android Studio的使用方法,通过Android Studio来进行安装和设定SDK,从而达到对安卓应用开发、编译和构建等目的,而实际上也可以直接安装SDK,这篇文章介绍一下相应的方法。
本文以CentOS 7.6作为示例安装环境进行说明
[root@liumiaocn ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
[root@liumiaocn ~]# uname -a
Linux liumiaocn 3.10.0-957.el7.x86_64 #1 SMP Thu Nov 8 23:39:32 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
[root@liumiaocn ~]#
[root@liumiaocn Demo]# java -version
openjdk version "1.8.0_232"
OpenJDK Runtime Environment (build 1.8.0_232-b09)
OpenJDK 64-Bit Server VM (build 25.232-b09, mixed mode)
[root@liumiaocn Demo]#
以Android SDK 26.1.1为例,不同操作系统的安装包文件下载路径如下所示:
类型 | 下载地址 |
---|---|
Windows no installer | https://dl.google.com/android/repository/sdk-tools-windows-4333796.zip |
MacOSX | https://dl.google.com/android/repository/sdk-tools-darwin-4333796.zip |
Linux | https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip |
[root@liumiaocn ~]# wget https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip
...省略
Saving to: ‘sdk-tools-linux-4333796.zip’
100%[==============================================================================================>] 154,582,459 9.87MB/s in 16s
...省略
[root@liumiaocn ~]#
执行命令:unzip sdk-tools-linux-4333796.zip
mkdir /usr/local/android
mv tools/ /usr/local/android/
安装准备:将上述zip文件进行解压会得到一个名为tools的目录,然后将其移动到/usr/local/android/目录下。
[root@liumiaocn tools]# pwd
/usr/local/android/tools
[root@liumiaocn tools]# ls
android bin emulator emulator-check lib mksdcard monitor NOTICE.txt proguard source.properties support
[root@liumiaocn tools]# ./android -h
*************************************************************************
The "android" command is deprecated.
For manual SDK, AVD, and project management, please use Android Studio.
For command-line tools, use tools/bin/sdkmanager and tools/bin/avdmanager
*************************************************************************
Invalid or unsupported command "-h"
Supported commands are:
android list target
android list avd
android list device
android create avd
android move avd
android delete avd
android list sdk
android update sdk
[root@liumiaocn tools]#
在步骤1中已经确认到此版本下android命令已经提示过时了,所以这里使用sdkmanager进行命令行方式的安装。详细sdkmanager的使用介绍可参看:
*
[root@liumiaocn bin]# pwd
/usr/local/android/tools/bin
[root@liumiaocn bin]# ls
apkanalyzer archquery avdmanager jobb lint monkeyrunner screenshot2 sdkmanager uiautomatorviewer
[root@liumiaocn bin]# ./sdkmanager --version
26.1.1
[root@liumiaocn bin]#
这里安装如下sdk的基本组件:
执行命令:
touch /root/.android/repositories.cfg
./sdkmanager platform-tools “platforms;android-29” “build-tools;29.0.2”
注意:有两个包中包含分号,需要用双引号引起来
[root@liumiaocn bin]# ./sdkmanager platform-tools "platforms;android-29" "build-tools;29.0.2"
License android-sdk-license: ] 10% Computing updates...
---------------------------------------
Terms and Conditions
...省略
14.7 The License Agreement, and your relationship with Google under the License Agreement, shall be governed by the laws of the State of California without regard to its conflict of laws provisions. You and Google agree to submit to the exclusive jurisdiction of the courts located within the county of Santa Clara, California to resolve any legal matter arising from the License Agreement. Notwithstanding this, you agree that Google shall still be allowed to apply for injunctive remedies (or an equivalent type of urgent legal relief) in any jurisdiction.
January 16, 2019
---------------------------------------
Accept? (y/N): y
[=======================================] 100% Unzipping... platform-tools/systr
[root@liumiaocn bin]#
上述操作执行完毕之后,会在tools同级创建安装的各个工具,详细如下所示:
[root@liumiaocn android]# pwd
/usr/local/android
[root@liumiaocn android]# ls
build-tools licenses platforms platform-tools tools
[root@liumiaocn android]#
[root@liumiaocn bin]# ./sdkmanager tools platform-tools extra-android-m2repository android-21 build-tools-29.0.2
Warning: File /root/.android/repositories.cfg could not be loaded.
Warning: Failed to find package extra-android-m2repository
[root@liumiaocn bin]# ] 10% Computing updates...
[root@liumiaocn bin]#