Added in API level 27

DelegateLastClassLoader

class DelegateLastClassLoader : PathClassLoader
kotlin.Any
   ↳ java.lang.ClassLoader
   ↳ dalvik.system.BaseDexClassLoader
   ↳ dalvik.system.PathClassLoader
   ↳ dalvik.system.DelegateLastClassLoader

A ClassLoader implementation that implements a delegate last lookup policy. For every class or resource this loader is requested to load, the following lookup order is employed:

  • The boot classpath is always searched first
  • Then, the list of dex files associated with this classloaders's dexPath is searched.
  • Finally, this classloader will delegate to the specified parent.

Summary

Public constructors

Equivalent to calling DelegateLastClassLoader(java.lang.String,java.lang.String,java.lang.ClassLoader,boolean) with librarySearchPath = null, delegateResourceLoading = true.

DelegateLastClassLoader(dexPath: String!, librarySearchPath: String!, parent: ClassLoader!)

Equivalent to calling DelegateLastClassLoader(java.lang.String,java.lang.String,java.lang.ClassLoader,boolean) with delegateResourceLoading = true.

DelegateLastClassLoader(dexPath: String, librarySearchPath: String?, parent: ClassLoader?, delegateResourceLoading: Boolean)

Creates a DelegateLastClassLoader that operates on a given dexPath and a librarySearchPath.

Public methods
URL!

Finds the resource with the given name.

Enumeration<URL!>!

Finds all the resources with the given name.

Protected methods
Class<*>!
loadClass(name: String!, resolve: Boolean)

Loads the class with the specified binary name.

Public constructors

DelegateLastClassLoader

Added in API level 27
DelegateLastClassLoader(
    dexPath: String!,
    parent: ClassLoader!)

Equivalent to calling DelegateLastClassLoader(java.lang.String,java.lang.String,java.lang.ClassLoader,boolean) with librarySearchPath = null, delegateResourceLoading = true.

DelegateLastClassLoader

Added in API level 27
DelegateLastClassLoader(
    dexPath: String!,
    librarySearchPath: String!,
    parent: ClassLoader!)

Equivalent to calling DelegateLastClassLoader(java.lang.String,java.lang.String,java.lang.ClassLoader,boolean) with delegateResourceLoading = true.

DelegateLastClassLoader

Added in API level 29
DelegateLastClassLoader(
    dexPath: String,
    librarySearchPath: String?,
    parent: ClassLoader?,
    delegateResourceLoading: Boolean)

Creates a DelegateLastClassLoader that operates on a given dexPath and a librarySearchPath. The dexPath should consist of one or more of the following, separated by File.pathSeparator, which is ":" on Android.

  • JAR/ZIP/APK files, possibly containing a "classes.dex" file as well as arbitrary resources.
  • Raw ".dex" files (not inside a zip file).
Unlike PathClassLoader, this classloader will attempt to locate classes (or resources) using the following lookup order.
  • The boot classpath is always searched first.
  • Then, the list of dex files contained in dexPath is searched./li>
  • Lastly, this classloader will delegate to the specified parent.
Note that this is in contrast to other standard classloaders that follow the delegation model. In those classloaders, the parent is always searched first. librarySearchPath specifies one more directories containing native library files, separated by File.pathSeparator.

Parameters
dexPath String: the list of jar/apk files containing classes and resources, delimited by File.pathSeparator, which defaults to ":" on Android.
This value cannot be null.
librarySearchPath String?: the list of directories containing native libraries, delimited by File.pathSeparator; may be null.
parent ClassLoader?: the parent class loader. May be null for the boot classloader.
delegateResourceLoading Boolean: whether to delegate resource loading to the parent if the resource is not found. This does not affect class loading delegation.

Public methods

getResource

Added in API level 27
fun getResource(name: String!): URL!

Finds the resource with the given name. A resource is some data (images, audio, text, etc) that can be accessed by class code in a way that is independent of the location of the code.

The name of a resource is a '/'-separated path name thatf identifies the resource.

Parameters
name String!: The resource name
Return
URL! URL object for reading the resource; null if the resource could not be found, a URL could not be constructed to locate the resource, the resource is in a package that is not opened unconditionally, or access to the resource is denied by the security manager.
Exceptions
java.lang.NullPointerException If name is null

getResources

Added in API level 27
fun getResources(name: String!): Enumeration<URL!>!

Finds all the resources with the given name. A resource is some data (images, audio, text, etc) that can be accessed by class code in a way that is independent of the location of the code.

The name of a resource is a /-separated path name that identifies the resource.

Parameters
name String!: The resource name
Return
Enumeration<URL!>! An enumeration of URL objects for the resource. If no resources could be found, the enumeration will be empty. Resources for which a URL cannot be constructed, are in a package that is not opened unconditionally, or access to the resource is denied by the security manager, are not returned in the enumeration.
Exceptions
java.io.IOException If I/O errors occur
java.lang.NullPointerException If name is null

Protected methods

loadClass

Added in API level 27
protected fun loadClass(
    name: String!,
    resolve: Boolean
): Class<*>!

Loads the class with the specified binary name. The default implementation of this method searches for classes in the following order:

  1. Invoke findLoadedClass(java.lang.String) to check if the class has already been loaded.
  2. Invoke the loadClass method on the parent class loader. If the parent is null the class loader built into the virtual machine is used, instead.
  3. Invoke the findClass(java.lang.String) method to find the class.

If the class was found using the above steps, and the resolve flag is true, this method will then invoke the resolveClass(java.lang.Class) method on the resulting Class object.

Subclasses of ClassLoader are encouraged to override findClass(java.lang.String), rather than this method.

Parameters
name String!: The binary name of the class
resolve Boolean: If true then resolve the class
Return
Class<*>! The resulting Class object
Exceptions
java.lang.ClassNotFoundException If the class could not be found