Example #1
0
  /**
   * Finds the named class in one of the dex files pointed at by this instance. This will find the
   * one in the earliest listed path element. If the class is found but has not yet been defined,
   * then this method will define it in the defining context that this instance was constructed
   * with.
   *
   * @param name of class to find
   * @param suppressed exceptions encountered whilst finding the class
   * @return the named class or {@code null} if the class is not found in any of the dex files
   */
  public Class findClass(String name, List<Throwable> suppressed) {
    for (Element element : dexElements) {
      DexFile dex = element.dexFile;

      if (dex != null) {
        Class clazz = dex.loadClassBinaryName(name, definingContext, suppressed);
        if (clazz != null) {
          return clazz;
        }
      }
    }
    if (dexElementsSuppressedExceptions != null) {
      suppressed.addAll(Arrays.asList(dexElementsSuppressedExceptions));
    }
    return null;
  }
Example #2
0
 /**
  * Constructs a {@code DexFile} instance, as appropriate depending on whether {@code
  * optimizedDirectory} is {@code null}.
  */
 private static DexFile loadDexFile(File file, File optimizedDirectory) throws IOException {
   if (optimizedDirectory == null) {
     return new DexFile(file);
   } else {
     String optimizedPath = optimizedPathFor(file, optimizedDirectory);
     return DexFile.loadDex(file.getPath(), optimizedPath, 0);
   }
 }