Android????Bug?????????
?????keep_thinking ???????[ 2016/7/5 17:24:25 ] ??????????????? ???????
????Android??classLoader????
????Android??Dalvik/ART???????????JAVA??JVM???????????????г????????????????????????????С?????????????????????????????????Class????????????ж???????????????????
??????Android????????????????Boot?????ClassLoader?????????????Щ??Framework?????????????Android?????????????Щ??????????APP???????????????Boot?????ClassLoader????????
????????APP????????????Щ??????APK??dex??????棬????APP?????????????????????ClassLoader???????????????dex????е???
????????????????????
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ClassLoader classLoader = getClassLoader();
Log.i("ClassLoader" ?? "classLoader " + classLoader.toString());
while (classLoader.getParent() != null) {
classLoader = classLoader.getParent();
if (classLoader != null) {
Log.i("ClassLoader"?? "classLoaderParent " + classLoader.toString());
}
}
}
?????????????
????I/ClassLoader: classLoader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.sunteng.classloader-1/base.apk"]??nativeLibraryDirectories=[/vendor/lib?? /system/lib]]]
????I/ClassLoader: classLoaderParent java.lang.BootClassLoader@2d0a3af7
?????????????2??Classloader??????????BootClassLoader??????????????????????????PathClassLoader?????????????????????????????app?????????
????Android??????????PathClassLoader??DexClassLoader
????PathClassLoader
??????????????????ClassLoader?????????????????????е???????????б?????????????????????? Android????????????????????????????????????
?????????????Android????????????????????????????????????????????????????????????????Android???е?apk?????
????DexClassLoader
??????????????ClassLoader????????.jar??.apk??????????classes.dex?????????????з????????????????ó?????????????
??????????????????sd???μ?dex??????????????????app???????
????Android?????PathClassLoader?????Android???????????????PathClassLoade????????BaseDexClassLoader??BaseDexClassLoader??д??findClass???????÷?????ClassLoader??????
#BaseDexClassLoader
@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
List<Throwable> suppressedExceptions = new ArrayList<Throwable>();
Class c = pathList.findClass(name?? suppressedExceptions);
if (c == null) {
ClassNotFoundException cnfe = new ClassNotFoundException("Didn't find class "" + name + "" on path: " + pathList);
for (Throwable t : suppressedExceptions) {
cnfe.addSuppressed(t);
}
throw cnfe;
}
return c;
}
?????????????BaseDexClassLoader??findClass??????и???pathList?????findClass??????pathList????????BaseDexClassLoader?????????new?????????????????DexPathList??????DexPathList.findClass?????????????
#DexPathList
public Class findClass(String name?? List<Throwable> suppressed) {
for (Element element : dexElements) {
DexFile dex = element.dexFile;
if (dex != null) {
Class clazz = dex.loadClassBinaryName(name?? definingContext?? suppressed);
if (clazz != null) {
return clazz;
}
}
}
if (dexElementsSuppressedExceptions != null) {
suppressed.addAll(Arrays.asList(dexElementsSuppressedExceptions));
}
return null;
}
#DexFile
public Class loadClassBinaryName(String name?? ClassLoader loader) {
return defineClass(name?? loader?? mCookie);
}
private native static Class defineClass(String name?? ClassLoader loader?? int cookie);
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11