Android Chinese API (140) -- DexFile

Source: Internet
Author: User

 

Preface

This chapter content dalvik. system. DexFile chapter, version for Android 4.0 r1, translated from: "A Year", welcome to visit his blog: "http://blog.csdn.net/mtding", thank you again "a year "! We look forward to your participation in translation of Android related information, contact me over140@gmail.com.

 

Statement

You are welcome to repost, but please keep the original source of the article :)

Blog Garden: http://www.cnblogs.com/

Android Chinese translation group: http://androidbox.sinaapp.com/

 

 

DexFile

Translator's signature: aonian

Link: http://blog.csdn.net/mtding

Version: Android 4.0 r1

 

Structure

Inheritance relationship

Public final class DexFile extends Object

Java. lang. Object

Dalvik. system. DexFile

 

Class Overview

Operate the DEX file. This class works similar to ZipFile. It is mainly used in the class loader.

Note: We do not directly open and read DEX files. They are mapped to memory in read-only mode by virtual machines.

 

Constructor

PublicDexFile(File file)

Open the DEX File through the specified File object. The specified file is usually a ZIP/JAR file containing "classes. dex ". The Virtual Machine will generate the corresponding file name under the directory/data/dalvik-cache and open it. If the system permission permits, it will be created or updated first. Do not pass the file name under the/data/dalvik-cache directory to it, because this file is considered in the initial state (before DEX is optimized ).

Parameters

File references the File object of the actual DEX File

Exception

An I/O exception occurs in IOException. For example, the object does not exist or has no access permission.

 

PublicDexFile(String fileName)

Open the DEX file of the specified file name. The specified file is usually a ZIP/JAR file containing "classes. dex ". The Virtual Machine will generate the corresponding file name under the directory/data/dalvik-cache and open it. If the system permission permits, it will be created or updated first. Do not pass the file name under the/data/dalvik-cache directory to it, because this file is considered in the initial state (before DEX is optimized ).

Parameters

FileName DEX file name.

Exception

An I/O exception occurs in IOException. For example, the object does not exist or has no access permission.

Common Methods

Public voidClose()

Close the DEX file.

You may not be able to release any resources. If the class from the DEX file is still alive, the DEX file cannot be unmapped.

Exception

IOException may cause an I/O exception while closing the file.

Public Enumeration <String>Entries()

Enumerate the class names in the DEX file.

Return Value

The DEX file contains an enumeration of class names. The class name type is in general internal format (such as java/lang/String ).

Public StringGetName()

Get (opened) DEX file name.

Return Value

File Name

 

Public static booleanIsDexOptNeeded(String fileName)

If the VM determines that the apk/jar file has expired, true is returned, and it should be passed through "dexopt" again. (Note: dexopt is an apk optimization tool)

Parameters

FileName is checked for the absolute path name of the apk/jar file.

Return Value

If you want to call dexopt to process files, true is returned; otherwise, false is returned.

Exception

The FileNotFoundException file is not readable, not a file, or does not exist.

IOException fileName is not a valid apk/jar file, or an error occurs when parsing the file.

NullPointerException fileName is null.

The DEX file optimized by StaleDexCacheError has expired and is located in the read-only partition.

 

Public ClassLoadClass(String name, ClassLoader loader)

Load a class. Returns the successfully loaded class. If the Failed class is returned, null is returned.

If you call it outside of the Class Loader, you will not get the expected result. In this case, use forName (String ).

This method will not throw the ClassNotFoundException exception when the class is not found, because it is unreasonable to throw an exception if the class is not found in the first DEX file we see.

Parameters

Name class name, which should be a "java/lang/String"

Loader tries to load the Class loader (in most cases, it is the caller of this method)

Return Value

The object corresponding to the class name. If the loading fails, null is returned.

Public static DexFileLoadDex(String sourcePathName, String outputPathName, int flags)

Open a DEX file and provide a file to save the optimized DEX data. If the optimized format already exists and is the latest, use it directly. If not, the VM will try to create a new one. This method is mainly used to download and execute DEX files in addition to the common application installation mechanism. Instead of calling this method directly in the application, you should use a Class Loader such as dalvik. system. DexClassLoader.

Parameters

SourcePathName contains the Jar or APK file "classes. dex. ("Raw DEX" may be extended in the future ".)

OutputPathName: The file that saves the optimized DEX data.

Flags enables the optional feature (not defined at present)

Return Value

A new or previously opened DexFile.

Exception

IOException cannot open input or output files.

 

Protected Methods

Protected voidFinalize()

Class end. Make sure that the DEX file is disabled.

Exception

An I/O exception occurs when IOException is disabled.

 

Supplement

Article Selection

Dalvik analysis-Class loading

Some methods for enabling another program

Android dynamic loading technology

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.