MultiDex.install源码解析(伪代码)
dexOpt操作是发生在哪里?
public static void install(Context context) {
List dexPathList = null;
if(systemVersion > 4.4){
return;
}else{
File dexFile = new File(context.getDataDir, "code_cache" + File.sperate + "secondary-dexes");
dexFile.mkdir();
MultiDexExtractor extractor = new MultiDexExtractor(sourceApk, dexDir);
if(!isModify){
dexPathList = extractor.load();
}else{
dexPathList = extractor.make();
}
}
ClassLoader loader = getClassLoader();
Field pathListField = MultiDex.findField(loader, "pathList");
Object dexPathList = pathListField.get(loader);
Method makeDexElements = MultiDex.findMethod(dexPathList, "makeDexElements", ArrayList.class, File.class, ArrayList.class);
(Object[])((Object[])makeDexElements.invoke(dexPathList, dexFile, optimizedDirectory, suppressedExceptions));
}
dexOpt操作发生在native层,由虚拟机来操作执行的。这个操作比较耗时。
|