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,
              )
          )
      write_action_env_to_bazelrc("ANDROID_NDK_VERSION", ndk_version)
  
      # 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.
      meta = open(
          os.path.join(android_ndk_home_path, "meta/platforms.json")
      )
      platforms = json.load(meta)
      meta.close()
      aliases = platforms["aliases"]
      api_levels = sorted(list(set([aliases[i] for i in aliases])))
  
      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=(lambda *_: True),
          error_msg="Android-%s is not present in the NDK path.",
      )
  
      return android_ndk_api_level
  
imports: import argparse
  import errno
  import glob
  import json
  import os
  import platform
  import re
  import subprocess
  import sys
label_desc: Use image node_id 30 for calling a global function with example usage: get_ndk_api_level(environ_cp, android_ndk_home_path) and returns: android_ndk_api_level