def _get_binary(binary_name, binary_paths_relative_to_android_sdk) -> str: sdk_location = AndroidSdkHelper._get_location_of_android_sdk() if not sdk_location: print_verbose('ANDROID_SDK_ROOT not defined') else: for relative_path in binary_paths_relative_to_android_sdk: binary_path = os.path.join(sdk_location, relative_path) if os.path.exists(binary_path): print_error('\"%s\" found at \"%s\"' % (binary_name, binary_path)) return binary_path else: print_error('\"%s\" not found at \"%s\"' % (binary_name, binary_path)) # Only works on Mac and GNU/Linux if PlatformHelper.on_linux() or PlatformHelper.on_mac(): return_code, stdout, stderr = PlatformHelper.execute_cmd( 'command -v %s' % binary_name) if return_code == 0: return stdout.strip() else: print_error('\"%s\" not in path' % binary_name) print_error_and_exit( 'Set ANDROID_SDK_ROOT environment variable to point to Android SDK root' )
def _get_all_java_versions() -> [str]: if PlatformHelper.on_linux(): return_code, stdout, stderr = PlatformHelper.execute_cmd(_GET_ALL_JAVA_VERSIONS_ON_LINUX) java_version_regex = 'java-([0-9]+.*?)/' elif PlatformHelper.on_mac(): java_version_regex = r'"([0-9]+\.[0-9]+)\..*"' return_code, stdout, stderr = PlatformHelper.execute_cmd(_GET_ALL_JAVA_VERSIONS_ON_MAC) else: print_error('Unsupported operating system') return [] if return_code != 0: print_error('Failed to list java versions') return [] output = '' output += stdout output += stderr versions = re.findall(java_version_regex, output) versions = set(versions) print_verbose('Versions are %s' % versions) return versions