code: def get_ndk_api_level(environ_cp, android_ndk_home_path):
      """Gets the appropriate NDK API level to use for the provided Android NDK path."""
  
      # First check to see if we're using a blessed version of the NDK.
      properties_path = "%s/source.properties" % android_ndk_home_path
      if is_windows() or is_cygwin():
          properties_path = cygpath(properties_path)
      with open(properties_path, "r") as f:
          filedata = f.read()
  
      revision = re.search(r"Pkg.Revision = (\d+)", filedata)
      if revision:
          ndk_version = revision.group(1)
      else:
          raise Exception("Unable to parse NDK revision.")
      if int(ndk_version) not in _SUPPORTED_ANDROID_NDK_VERSIONS:
          print(
              "WARNING: The NDK version in %s is %s, which is not "
              "supported by Bazel (officially supported versions: %s). Please use "
              "another version. Compiling Android targets may result in confusing "
              "errors.\n"
              % (
                  android_ndk_home_path,
                  ndk_version,
                  _SUPPORTED_ANDROID_NDK_VERSIONS,
              )
          )
  
      # Now grab the NDK API level to use. Note that this is different from the
      # SDK API level, as the NDK API level is effectively the *min* target SDK
      # version.
      platforms = os.path.join(android_ndk_home_path, "platforms")
      api_levels = sorted(os.listdir(platforms))
      api_levels = [
          x.replace("android-", "")
          for x in api_levels
          if "android-" in x
      ]
  
      def valid_api_level(api_level):
          return os.path.exists(
              os.path.join(
                  android_ndk_home_path,
                  "platforms",
                  "android-" + api_level,
              )
          )
  
      android_ndk_api_level = prompt_loop_or_load_from_env(
          environ_cp,
          var_name="ANDROID_NDK_API_LEVEL",
          var_default="26",  # 26 is required to support AHardwareBuffer.
          ask_for_var=(
              "Please specify the (min) Android NDK API level to use. "
              "[Available levels: %s]"
          )
          % api_levels,
          check_success=valid_api_level,
          error_msg="Android-%s is not present in the NDK path.",
      )
  
      return android_ndk_api_level
  
imports: import os
  import platform
  import re
  import subprocess
  import sys
label_desc: Use image node_id 21 for calling a global function with example usage: get_ndk_api_level(environ_cp, android_ndk_home_path) and returns: android_ndk_api_level, os