public static int magicToApi(byte[] magic) {
    if (magic.length != 8) {
      return -1;
    }

    if ((magic[0] != 'd')
        || (magic[1] != 'e')
        || (magic[2] != 'x')
        || (magic[3] != '\n')
        || (magic[7] != '\0')) {
      return -1;
    }

    String version = "" + ((char) magic[4]) + ((char) magic[5]) + ((char) magic[6]);

    if (version.equals(VERSION_FOR_API_13)) {
      return API_NO_EXTENDED_OPCODES;
    } else if (version.equals(VERSION_FOR_API_24)) {
      return API_DEFINE_INTERFACE_METHODS;
    } else if (version.equals(VERSION_FOR_API_26)) {
      return API_METHOD_HANDLES;
    } else if (version.equals(VERSION_FOR_API_28)) {
      return API_CONST_METHOD_HANDLE;
    } else if (version.equals(VERSION_CURRENT)) {
      return API_CURRENT;
    }

    return -1;
  }
Returns the API level corresponding to the given magic number, or {@code -1} if the given array
is not a well-formed dex file magic number.

@param magic array of bytes containing DEX file magic string
@return API level corresponding to magic string if valid, -1 otherwise.
android/android_framework/dex-maker/src/main/java/com/android/dex/DexFormat.java