Skip to content

How to check installed Android SDK versions?

Snoy-Kuo edited this page Mar 23, 2022 · 1 revision

Description

I want to check what Android SDK versions are available on target machines using command-line.

Dev env

  • macOS 11.6 (Big Sur) x64
  • Android Studio Bumblebee Patch 1
  • Android SDK version 31
  • Android Gradle Plugin: 4.1.3
  • Gradle: 6.5
  • Gradle JDK: 1.8
  • Kotlin: 1.6.10

Build env

  • Ubuntu 18.04.4 LTS
  • Android SDK version 31
  • Gradle: 6.6
  • JDK: 11

Tried approaches

  • 2 Ways to Check Android SDK Versions (2022)
    • avdmanager list target
      => It works on mac, only if you use the right avdmanager. In my case, use sh ${ANDROID_SDK_ROOT}/cmdline-tools/latest/bin/avdmanager list target. But this not work in my build env. Maybe cmdline-tools are not installed.
    • android list target
      => Not work for me. This command should be sh ${ANDROID_SDK_ROOT}/tools/android list target, if ${ANDROID_SDK_ROOT}/tools/ not in PATH env var. And the command shows the following error message: 'The "android" command is deprecated.'
  • How to determine the version of android SDK installed in computer?
    • /tools/bin/sdkmanager --version
      => Not work for me. "/tools/bin/sdkmanager" will cause NoClassDefFoundError. The correct path for me is "${ANDROID_SDK_ROOT}/cmdline-tools/latest/bin/sdkmanager". But "--version" shows the sdkmanager version, not sdk version. If you want to get installed sdk version, you can use sh ${ANDROID_SDK_ROOT}/cmdline-tools/latest/bin/sdkmanager --list_installed. It shows but only sdk, but all tools and images installed. To show sdk only, you can use sh ${ANDROID_SDK_ROOT}/cmdline-tools/latest/bin/sdkmanager --list_installed | sed -n 's/.*platforms;//p'. But this not work in my build env. Maybe cmdline-tools are not installed.
  • Failed to run sdkmanager --list with Java 9
    • /tools/bin/sdkmanager --list with sdkmanager script modified. Where update the file DEFAULT_JVM_OPTS='"-Dcom.android.sdklib.toolsdir=$APP_HOME" -XX:+IgnoreUnrecognizedVMOptions --add-modules java.se.ee'.
      => Not work for me.
  • Print the sdk platforms' folders
    • ls ${ANDROID_SDK_ROOT}/platforms
      => It works!

Solutions

  • Print the sdk platforms' folders
    • ls ${ANDROID_SDK_ROOT}/platforms