设置Android SDK命令行工具没有Android Studio
#发展 #android #adb #commandline

case01:为Android模拟器设置

  1. 下载Android SDK Command-Line Tools

  2. 安装必要的工具:

    # create a directory for the cli-tools, and move the .zip file into the directory
    mkdir android_sdk
    cd android_sdk
    mv <PATH_TO_YOUR_DOWNLOADED_ZIP_FILE> .
    # unzip the downloaded file, and put the contents in the new directory 'latest/'
    unzip commandlinetools-<YOUR_PLATFORM>-8512546_latest.zip
    mkdir cmdline-tools/latest
    cd cmdline-tools/latest
    mv ../* .
    # The hierarchy of the 'android_sdk/':
    └- android_sdk/
     ├- cmdline-tools/
        ├- latest/
           ├- bin/
           ├- lib/
           ├- NOTICE.txt
           └- source.properties
    # Install platform and build tools
    # You can fetch the complete list of available packages via:
    bin/sdkmanager --list
    # Install the desired package and tools via:
    bin/sdkmanager --install "system-images;android-33;google_apis;x86_64"
    # The above command will download and install the tools in the sdk_root (android_sdk/)
    
  3. 下载并安装模拟器:

    bin/sdkmanager --install "emulator" 
    
  4. 创建一个新的AVD设备:

    bin/avdmanager create avd -n mytestdevice -k "system-images;android-33;google_apis;x86_64"
    
  5. 检查AVD设备是否可用:

    # go to the 'emulator/' directory, and run the command
    cd ../../emulator
    ./emulator -list-avds
    # Now you should see your newly created avd device `mytestdevice`
    
  6. 运行模拟器

    ./emulator -avd mytestdevice
    

case02:为真实的Android设备设置

  1. 转到official site并下载 SDK平台 - 工具

  2. 解压缩.zip文件。您可以在提取的目录中找到 adb 二进制。

    cd platform-tools
    # Show every available Android device
    ./adb devices