publicclassBaseDexClassLoaderextendsClassLoader {privatefinalDexPathList pathList; /** * Constructs an instance. * * @param dexPath the list of jar/apk files containing classes and * resources, delimited by {@code File.pathSeparator}, which * defaults to {@code ":"} on Android * @param optimizedDirectory directory where optimized dex files * should be written; may be {@code null} * @param libraryPath the list of directories containing native * libraries, delimited by {@code File.pathSeparator}; may be * {@code null} * @param parent the parent class loader */publicBaseDexClassLoader(String dexPath,File optimizedDirectory,String libraryPath,ClassLoader parent) { super(parent);this.pathList=newDexPathList(this, dexPath, libraryPath, optimizedDirectory); } @OverrideprotectedClass<?> findClass(String name) throwsClassNotFoundException {List<Throwable> suppressedExceptions =newArrayList<Throwable>();Class c =pathList.findClass(name, suppressedExceptions);if (c ==null) { ClassNotFoundException cnfe = new ClassNotFoundException("Didn't find class \"" + name + "\" on path: " + pathList);
for (Throwable t : suppressedExceptions) {cnfe.addSuppressed(t); }throw cnfe; }return c; }}
/*package*/finalclassDexPathList {privatestaticfinalString DEX_SUFFIX =".dex";privatestaticfinalString JAR_SUFFIX =".jar";privatestaticfinalString ZIP_SUFFIX =".zip";privatestaticfinalString APK_SUFFIX =".apk"; /** class definition context */privatefinalClassLoader definingContext; /** * List of dex/resource (class path) elements. * Should be called pathElements, but the Facebook app uses reflection * to modify 'dexElements' (http://b/7726934). */privatefinalElement[] dexElements; /** * 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 */publicClassfindClass(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)); }returnnull; }}