Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Nested Classes](https://developer.android.com/reference/dalvik/system/DexFile#nestedclasses) \| [Ctors](https://developer.android.com/reference/dalvik/system/DexFile#pubctors) \| [Methods](https://developer.android.com/reference/dalvik/system/DexFile#pubmethods) \| [Protected Methods](https://developer.android.com/reference/dalvik/system/DexFile#promethods) \| [Inherited Methods](https://developer.android.com/reference/dalvik/system/DexFile#inhmethods)

# DexFile


`
public

final

class
DexFile
`


`

extends https://developer.android.com/reference/java/lang/Object


`

`


`

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | dalvik.system.DexFile |

<br />

*** ** * ** ***

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

Applications should not instantiate this class. 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 `https://developer.android.com/reference/dalvik/system/PathClassLoader` instead. **Non-static APIs
will be removed in a future Android release**.

## Summary

| ### Nested classes ||
|---|---|
| ` class` | `https://developer.android.com/reference/dalvik/system/DexFile.OptimizationInfo` Encapsulates information about the optimizations performed on a dex file. |

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/dalvik/system/DexFile#DexFile(java.io.File)(https://developer.android.com/reference/java/io/File file) ` *This constructor is deprecated. Applications should use one of the standard classloaders such as `https://developer.android.com/reference/dalvik/system/PathClassLoader` instead. **This API will be removed in a future Android release**.* |
| ` https://developer.android.com/reference/dalvik/system/DexFile#DexFile(java.lang.String)(https://developer.android.com/reference/java/lang/String fileName) ` *This constructor is deprecated. Applications should use one of the standard classloaders such as `https://developer.android.com/reference/dalvik/system/PathClassLoader` instead. **This API will be removed in a future Android release**.* |

| ### Public methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/dalvik/system/DexFile#close()() ` *This method was deprecated in API level 26. Applications should use one of the standard classloaders such as `https://developer.android.com/reference/dalvik/system/PathClassLoader` instead. **This API will be removed in a future Android release**.* |
| ` https://developer.android.com/reference/java/util/Enumeration<https://developer.android.com/reference/java/lang/String>` | ` https://developer.android.com/reference/dalvik/system/DexFile#entries()() ` *This method was deprecated in API level 26. Applications should use one of the standard classloaders such as `https://developer.android.com/reference/dalvik/system/PathClassLoader` instead. **This API will be removed in a future Android release**.* |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/dalvik/system/DexFile#getName()() ` *This method was deprecated in API level 26. Applications should use one of the standard classloaders such as `https://developer.android.com/reference/dalvik/system/PathClassLoader` instead. **This API will be removed in a future Android release**.* |
| ` static boolean` | ` https://developer.android.com/reference/dalvik/system/DexFile#isDexOptNeeded(java.lang.String)(https://developer.android.com/reference/java/lang/String fileName) ` *This method was deprecated in API level 26. Use `Artd.getDexoptNeeded` instead.* |
| ` https://developer.android.com/reference/java/lang/Class<T>` | ` https://developer.android.com/reference/dalvik/system/DexFile#loadClass(java.lang.String,%20java.lang.ClassLoader)(https://developer.android.com/reference/java/lang/String name, https://developer.android.com/reference/java/lang/ClassLoader loader) ` *This method was deprecated in API level 26. Applications should use one of the standard classloaders such as `https://developer.android.com/reference/dalvik/system/PathClassLoader` instead. **This API will be removed in a future Android release**.* |
| ` static https://developer.android.com/reference/dalvik/system/DexFile` | ` https://developer.android.com/reference/dalvik/system/DexFile#loadDex(java.lang.String,%20java.lang.String,%20int)(https://developer.android.com/reference/java/lang/String sourcePathName, https://developer.android.com/reference/java/lang/String outputPathName, int flags) ` *This method was deprecated in API level 26. Applications should use one of the standard classloaders such as `https://developer.android.com/reference/dalvik/system/PathClassLoader` instead. **This API will be removed in a future Android release**.* |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/dalvik/system/DexFile#toString()() ` Returns a string representation of the object. |

| ### Protected methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/dalvik/system/DexFile#finalize()() ` Called when the class is finalized. |

### Inherited methods

From class `

https://developer.android.com/reference/java/lang/Object

` `


https://developer.android.com/reference/java/lang/Object` `
https://developer.android.com/reference/java/lang/Object#clone()()
`

Creates and returns a copy of this object.


`


boolean` `
https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj)
`

Indicates whether some other object is "equal to" this one.


`


void` `
https://developer.android.com/reference/java/lang/Object#finalize()()
`

Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object.


`


final

https://developer.android.com/reference/java/lang/Class<?>` `
https://developer.android.com/reference/java/lang/Object#getClass()()
`

Returns the runtime class of this `Object`.


`


int` `
https://developer.android.com/reference/java/lang/Object#hashCode()()
`

Returns a hash code value for the object.


`


final

void` `
https://developer.android.com/reference/java/lang/Object#notify()()
`

Wakes up a single thread that is waiting on this object's
monitor.


`


final

void` `
https://developer.android.com/reference/java/lang/Object#notifyAll()()
`

Wakes up all threads that are waiting on this object's monitor.


`


https://developer.android.com/reference/java/lang/String` `
https://developer.android.com/reference/java/lang/Object#toString()()
`

Returns a string representation of the object.


`


final

void` `
https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos)
`

Causes the current thread to wait until it is awakened, typically
by being *notified* or *interrupted*, or until a
certain amount of real time has elapsed.


`


final

void` `
https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis)
`

Causes the current thread to wait until it is awakened, typically
by being *notified* or *interrupted*, or until a
certain amount of real time has elapsed.


`


final

void` `
https://developer.android.com/reference/java/lang/Object#wait()()
`

Causes the current thread to wait until it is awakened, typically
by being *notified* or *interrupted*.


## Public constructors

### DexFile

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public DexFile (File file)
```


**This constructor is deprecated.**   

Applications should use one of the standard classloaders such
as `https://developer.android.com/reference/dalvik/system/PathClassLoader` instead. **This API will be removed
in a future Android release**.

Opens a DEX file from a given File object.

<br />

| Parameters ||
|---|---|
| `file` | `File` <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` |   |

### DexFile

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public DexFile (String fileName)
```


**This constructor is deprecated.**   

Applications should use one of the standard classloaders such
as `https://developer.android.com/reference/dalvik/system/PathClassLoader` instead. **This API will be removed
in a future Android release**.

Opens a DEX file from a given filename.

<br />

| Parameters ||
|---|---|
| `fileName` | `String` <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` |   |

## Public methods

### close

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level
26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void close ()
```


**This method was deprecated
in API level 26.**   

Applications should use one of the standard classloaders such
as `https://developer.android.com/reference/dalvik/system/PathClassLoader` instead. **This API will be removed
in a future Android release**.

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.

<br />

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | if an I/O error occurs during closing the file, which normally should not happen |

### entries

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level
26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Enumeration<String> entries ()
```


**This method was deprecated
in API level 26.**   

Applications should use one of the standard classloaders such
as `https://developer.android.com/reference/dalvik/system/PathClassLoader` instead. **This API will be removed
in a future Android release**.

Enumerate the names of the classes in this DEX file.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/Enumeration<https://developer.android.com/reference/java/lang/String>` | an enumeration of names of classes contained in the DEX file, in the usual internal form (like "java/lang/String"). <br /> |

### getName

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level
26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public String getName ()
```


**This method was deprecated
in API level 26.**   

Applications should use one of the standard classloaders such
as `https://developer.android.com/reference/dalvik/system/PathClassLoader` instead. **This API will be removed
in a future Android release**.

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

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | the file name <br /> |

### isDexOptNeeded

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level
26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static boolean isDexOptNeeded (String fileName)
```


**This method was deprecated
in API level 26.**   

Use `Artd.getDexoptNeeded` instead.

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

<br />

| Parameters ||
|---|---|
| `fileName` | `String`: the absolute path to the apk/jar file to examine. <br /> |

| Returns ||
|---|---|
| `boolean` | true if dexopt should be called on the file, false otherwise. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/FileNotFoundException` | if fileName is not readable, not a file, or not present. |
| `https://developer.android.com/reference/java/io/IOException` | if fileName is not a valid apk/jar file or if problems occur while parsing it. |
| `https://developer.android.com/reference/java/lang/NullPointerException` | if fileName is null. |

### loadClass

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level
26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Class<T> loadClass (String name, 
                ClassLoader loader)
```


**This method was deprecated
in API level 26.**   

Applications should use one of the standard classloaders such
as `https://developer.android.com/reference/dalvik/system/PathClassLoader` instead. **This API will be removed
in a future Android release**.

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 `https://developer.android.com/reference/java/lang/Class#forName(java.lang.String)` instead.


The method does not throw `https://developer.android.com/reference/java/lang/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.

<br />

| Parameters ||
|---|---|
| `name` | `String`: the class name, which should look like "java/lang/String" <br /> |
| `loader` | `ClassLoader`: the class loader that tries to load the class (in most cases the caller of the method <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/Class<T>` | the `https://developer.android.com/reference/java/lang/Class` object representing the class, or `null` if the class cannot be loaded <br /> |

### loadDex

Added in [API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level
26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public 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 `https://developer.android.com/reference/dalvik/system/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.

<br />

| Parameters ||
|---|---|
| `sourcePathName` | `String` <br /> |
| `outputPathName` | `String` <br /> |
| `flags` | `int` <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/dalvik/system/DexFile` | <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` |   |

### toString

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public String toString ()
```

Returns a string representation of the object.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | a string representation of the object. <br /> |

## Protected methods

### finalize

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected void finalize ()
```

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

Note: dex2oat bypasses finalization during multi-process app image generation by dropping the
java.lang.ref.FinalizerReference.head poimter before GC.

<br />

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | if an I/O error occurs during closing the file, which normally should not happen |
| `https://developer.android.com/reference/java/lang/Throwable` |   |