Skip to content

Most visited

Recently visited

navigation

DexFile

public final class DexFile
extends Object

java.lang.Object
   ↳ dalvik.system.DexFile


This class was deprecated in API level 26.
This class should not be used directly by applications. It will hurt performance in most cases and will lead to incorrect execution of bytecode in the worst case. Applications should use one of the standard classloaders such as PathClassLoader instead. This API will be removed in a future Android release.

Loads DEX files. This class is meant for internal use and should not be used by applications.

Summary

Public constructors

DexFile(File file)

This constructor was deprecated in API level 26. Applications should use one of the standard classloaders such as PathClassLoader instead. This API will be removed in a future Android release.

DexFile(String fileName)

This constructor was deprecated in API level 26. Applications should use one of the standard classloaders such as PathClassLoader instead. This API will be removed in a future Android release.

Public methods

void close()

Closes the DEX file.

Enumeration<String> entries()

Enumerate the names of the classes in this DEX file.

String getName()

Gets the name of the (already opened) DEX file.

static boolean isDexOptNeeded(String fileName)

Returns true if the VM believes that the apk/jar file is out of date and should be passed through "dexopt" again.

Class loadClass(String name, ClassLoader loader)

Loads a class.

static DexFile loadDex(String sourcePathName, String outputPathName, int flags)

This method was deprecated in API level 26. Applications should use one of the standard classloaders such as PathClassLoader instead. This API will be removed in a future Android release.

String toString()

Returns a string representation of the object.

Protected methods

void finalize()

Called when the class is finalized.

Inherited methods

From class java.lang.Object

Public constructors

DexFile

added in API level 1
DexFile (File file)

This constructor was deprecated in API level 26.
Applications should use one of the standard classloaders such as PathClassLoader instead. This API will be removed in a future Android release.

Opens a DEX file from a given File object.

Parameters
file File

Throws
IOException

DexFile

added in API level 1
DexFile (String fileName)

This constructor was deprecated in API level 26.
Applications should use one of the standard classloaders such as PathClassLoader instead. This API will be removed in a future Android release.

Opens a DEX file from a given filename.

Parameters
fileName String

Throws
IOException

Public methods

close

added in API level 1
void close ()

Closes the DEX file.

This may not be able to release all of the resources. If classes from this DEX file are still resident, the DEX file can't be unmapped. In the case where we do not release all the resources, close is called again in the finalizer.

Throws
IOException if an I/O error occurs during closing the file, which normally should not happen

entries

added in API level 1
Enumeration<String> entries ()

Enumerate the names of the classes in this DEX file.

Returns
Enumeration<String> an enumeration of names of classes contained in the DEX file, in the usual internal form (like "java/lang/String").

getName

added in API level 1
String getName ()

Gets the name of the (already opened) DEX file.

Returns
String the file name

isDexOptNeeded

added in API level 1
boolean isDexOptNeeded (String fileName)

Returns true if the VM believes that the apk/jar file is out of date and should be passed through "dexopt" again.

Parameters
fileName String: the absolute path to the apk/jar file to examine.

Returns
boolean true if dexopt should be called on the file, false otherwise.

Throws
FileNotFoundException if fileName is not readable, not a file, or not present.
IOException if fileName is not a valid apk/jar file or if problems occur while parsing it.
NullPointerException if fileName is null.

loadClass

added in API level 1
Class loadClass (String name, 
                ClassLoader loader)

Loads a class. Returns the class on success, or a null reference on failure.

If you are not calling this from a class loader, this is most likely not going to do what you want. Use forName(String) instead.

The method does not throw ClassNotFoundException if the class isn't found because it isn't reasonable to throw exceptions wildly every time a class is not found in the first DEX file we look at.

Parameters
name String: the class name, which should look like "java/lang/String"

loader ClassLoader: the class loader that tries to load the class (in most cases the caller of the method

Returns
Class the Class object representing the class, or null if the class cannot be loaded

loadDex

added in API level 3
DexFile loadDex (String sourcePathName, 
                String outputPathName, 
                int flags)

This method was deprecated in API level 26.
Applications should use one of the standard classloaders such as PathClassLoader instead. This API will be removed in a future Android release.

Open a DEX file, specifying the file in which the optimized DEX data should be written. If the optimized form exists and appears to be current, it will be used; if not, the VM will attempt to regenerate it.

Parameters
sourcePathName String

outputPathName String

flags int

Returns
DexFile

Throws
IOException

toString

added in API level 1
String toString ()

Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.

The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:

 getClass().getName() + '@' + Integer.toHexString(hashCode())
 

Returns
String a string representation of the object.

Protected methods

finalize

added in API level 1
void finalize ()

Called when the class is finalized. Makes sure the DEX file is closed.

Throws
IOException if an I/O error occurs during closing the file, which normally should not happen
Throwable
This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a one-minute survey?
Help us improve Android tools and documentation.