tools/android/sdk_updater/update_sdk.py
def _FindPackageVersion(package, sdk_root):
  """Find sdk package version.

  Two options for package version:
    1) Use the version in name if package name contains ';version'
    2) For simple name package, search its version from 'Installed packages'
       via `sdkmanager --list`

  Args:
    package: The Android SDK package.
    sdk_root: The Android SDK root path.

  Returns:
    The version of package.

  Raises:
    Exception: cannot find the version of package.
  """
  sdkmanager_list_cmd = [
      _SDKMANAGER_PATH,
      '--list',
      '--sdk_root=%s' % sdk_root,
  ]

  if package in _DEFAULT_PACKAGES_DICT:
    # Get the version after ';' from package name
    package = _DEFAULT_PACKAGES_DICT[package]
    return package.split(';')[1]
  else:
    # Get the package version via `sdkmanager --list`. The logic is:
    # Check through 'Installed packages' which is at the first section of
    # `sdkmanager --list` output, example:
    #   Installed packages:=====================] 100% Computing updates...
    #     Path                        | Version | Description
    #     -------                     | ------- | -------
    #     build-tools;27.0.3          | 27.0.3  | Android SDK Build-Tools 27.0.3
    #     emulator                    | 26.0.3  | Android Emulator
    #     platforms;android-27        | 1       | Android SDK Platform 27
    #     tools                       | 26.1.1  | Android SDK Tools
    #
    #   Available Packages:
    #   ....
    # When found a line containing the package path, grap its version between
    # the first and second '|'. Since the 'Installed packages' list section ends
    # by the first new line, the check loop should be ended when reaches a '\n'.
    output = subprocess.check_output(sdkmanager_list_cmd)
    for line in output.splitlines():
      if ' ' + package + ' ' in line:
        # if found package path, catch its version which in the first '|...|'
        return line.split('|')[1].strip()
      if line == '\n':  # Reaches the end of 'Installed packages' list
        break
    raise Exception('Cannot find the version of package %s' % package)
Find sdk package version.

  Two options for package version:
    1) Use the version in name if package name contains ';version'
    2) For simple name package, search its version from 'Installed packages'
       via `sdkmanager --list`

  Args:
    package: The Android SDK package.
    sdk_root: The Android SDK root path.

  Returns:
    The version of package.

  Raises:
    Exception: cannot find the version of package.
  
Find sdk package version.
Two options for package version:
1) Use the version in name if package name contains ';version'
2) For simple name package, search its version from 'Installed packages'
via `sdkmanager --list`
Find sdk package version . Two options for package version : 1 ) Use the version in name if package name contains ' ; version ' 2 ) For simple name package search its version from ' Installed packages ' via ` sdkmanager -- list `
def _FindPackageVersion(package, sdk_root):
  sdkmanager_list_cmd = [
      _SDKMANAGER_PATH,
      '--list',
      '--sdk_root=%s' % sdk_root,
  ]
  if package in _DEFAULT_PACKAGES_DICT:
    package = _DEFAULT_PACKAGES_DICT[package]
    return package.split(';')[1]
  else:
       Available Packages:
       ....
     When found a line containing the package path, grap its version between
     the first and second '|'. Since the 'Installed packages' list section ends
     by the first new line, the check loop should be ended when reaches a '\n'.
    output = subprocess.check_output(sdkmanager_list_cmd)
    for line in output.splitlines():
      if ' ' + package + ' ' in line:
         if found package path, catch its version which in the first '|...|'
        return line.split('|')[1].strip()
      if line == '\n':   Reaches the end of 'Installed packages' list
        break
    raise Exception('Cannot find the version of package %s' % package)
def _FindPackageVersion ( package , sdk_root ) : sdkmanager_list_cmd = [ _SDKMANAGER_PATH , '--list' , '--sdk_root=%s' % sdk_root , ] if package in _DEFAULT_PACKAGES_DICT : package = _DEFAULT_PACKAGES_DICT [ package ] return package . split ( ';' ) [ 1 ] else : output = subprocess . check_output ( sdkmanager_list_cmd ) for line in output . splitlines ( ) : if ' ' + package + ' ' in line : return line . split ( '|' ) [ 1 ] . strip ( ) if line == '\n' : break raise Exception ( 'Cannot find the version of package %s' % package )
Find sdk package version.
Find sdk package version .
"""Find sdk package version.

  Two options for package version:
    1) Use the version in name if package name contains ';version'
    2) For simple name package, search its version from 'Installed packages'
       via `sdkmanager --list`

  Args:
    package: The Android SDK package.
    sdk_root: The Android SDK root path.

  Returns:
    The version of package.

  Raises:
    Exception: cannot find the version of package.
  """ # Get the version after ';' from package name # Get the package version via `sdkmanager --list`. The logic is: # Check through 'Installed packages' which is at the first section of # `sdkmanager --list` output, example: #   Installed packages:=====================] 100% Computing updates... #     Path                        | Version | Description #     -------                     | ------- | ------- #     build-tools;27.0.3          | 27.0.3  | Android SDK Build-Tools 27.0.3 #     emulator                    | 26.0.3  | Android Emulator #     platforms;android-27        | 1       | Android SDK Platform 27 #     tools                       | 26.1.1  | Android SDK Tools # #   Available Packages: #   .... # When found a line containing the package path, grap its version between # the first and second '|'. Since the 'Installed packages' list section ends # by the first new line, the check loop should be ended when reaches a '\n'. # if found package path, catch its version which in the first '|...|' # Reaches the end of 'Installed packages' list
The version of package.
The version of package .
cannot find the version of package.
cannot find the version of package .
Exception
package
The Android SDK package.
The Android SDK package .
sdk_root
The Android SDK root path.
The Android SDK root path .