1.下载

地址:https://developer.android.google.cn/studio,拉到最下面找到`Command line tools only`

下载Linux版Command line tools

2.安装

  • 将安装包commandlinetools-linux-9477386_latest.zip上传至服务器/usr/local/src

  • 解压并进入

    1
    2
    3
    4
    unzip commandlinetools-linux-9477386_latest.zip # 解压压缩包
    cd cmdline-tools # 解压以后的文件名字为cmdline-tools
    mkdir latest # 创建latest【安装优化工具是必须有此文件夹】
    mv !(latest) latest # 将cmdline-tools里所有文件都移动到latest里
  • 安装构建优化工具

    1
    2
    cd /usr/local/src/cmdline-tools/bin
    ./sdkmanager --install "build-tools;31.0.0" //安装想要的工具
  • 安装以后build-tools会在cmdline-tools的同级目录下

    目录展示

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    [root@localhost 31.0.0]# pwd
    /usr/local/src/build-tools/31.0.0

    [root@localhost 31.0.0]# ll
    total 23712
    -rwxr-xr-x 1 root root 1573784 Feb 20 17:30 aapt
    -rwxr-xr-x 1 root root 6039328 Feb 20 17:30 aapt2
    -rw-r--r-- 1 root root 343 Feb 20 17:30 aarch64-linux-android-ld
    -rwxr-xr-x 1 root root 4904768 Feb 20 17:30 aidl
    -rwxr-xr-x 1 root root 2959 Feb 20 17:30 apksigner
    -rw-r--r-- 1 root root 343 Feb 20 17:30 arm-linux-androideabi-ld
    -rwxr-xr-x 1 root root 38712 Feb 20 17:30 bcc_compat
    -rw-r--r-- 1 root root 18159 Feb 20 17:30 core-lambda-stubs.jar
    -rwxr-xr-x 1 root root 2598 Feb 20 17:30 d8
    -rwxr-xr-x 1 root root 7951520 Feb 20 17:30 dexdump
    -rw-r--r-- 1 root root 343 Feb 20 17:30 i686-linux-android-ld
    drwxr-xr-x 2 root root 4096 Feb 20 17:30 lib
    drwxr-xr-x 2 root root 4096 Feb 20 17:30 lib64
    -rwxr-xr-x 1 root root 647 Feb 20 17:30 lld
    drwxr-xr-x 2 root root 4096 Feb 20 17:30 lld-bin
    -rwxr-xr-x 1 root root 1088832 Feb 20 17:30 llvm-rs-cc
    -rwxr-xr-x 1 root root 4732 Feb 20 17:30 mainDexClasses
    -rw-r--r-- 1 root root 310 Feb 20 17:30 mainDexClassesNoAapt.rules
    -rw-r--r-- 1 root root 758 Feb 20 17:30 mainDexClasses.rules
    -rw-r--r-- 1 root root 343 Feb 20 17:30 mipsel-linux-android-ld
    -rw-r--r-- 1 root root 766444 Feb 20 17:30 NOTICE.txt
    -rw-r--r-- 1 root root 18339 Feb 20 17:30 package.xml
    drwxr-xr-x 5 root root 4096 Feb 20 17:30 renderscript
    -rw-r--r-- 1 root root 17 Feb 20 17:30 runtime.properties
    -rw-r--r-- 1 root root 63 Feb 20 17:30 source.properties
    -rwxr-xr-x 1 root root 1533904 Feb 20 17:30 split-select
    -rw-r--r-- 1 root root 343 Feb 20 17:30 x86_64-linux-android-ld
    -rwxr-xr-x 1 root root 248360 Feb 20 17:30 zipalign

  • 添加环境变量

    1
    ln -sf/usr/local/src/build-tools/31.0.0/zipalign /usr/local/bin/zipalign