Android ClassLoader源码
hint:源码基于android8.0 sdk版本:26

image.png
ClassLoader#loadClass(java.lang.String)
protected Class<?> loadClass(String name, boolean resolve)
throws ClassNotFoundException
{
// First, check if the class has already been loaded
Class<?> c = findLoadedClass(name);
if (c == null) {
try {
if (parent != null) {
c = parent.loadClass(name, false);
} else {
c = findBootstrapClassOrNull(name);
}
} catch (ClassNotFoundException e) {
// ClassNotFoundException thrown if class not found
// from the non-null parent class loader
}
if (c == null) {
// If still not found, then invoke findClass in order
// to find the class.
c = findClass(name);
}
}
return c;
}
子类BaseDexClassLoader
private final DexPathList pathList;
findClass

image.png
DexPathList
private Element[] dexElements; 构造初始化
Element

image.png
DexPathList--makeDexElements

image.png
DexPathList--findClass

image.png
Element--findClass

image.png
DexPathList--loadDexFile

image.png
DexFile

image.png
DexFile--loadDex

image.png
DexFile--loadClassBinaryName、defineClass、defineClassNative

image.png
Android8.0+主角--PathClassLoader

image.png
本文标题:Android ClassLoader源码
本文链接:https://www.haomeiwen.com/subject/tunleltx.html
网友评论