-
Notifications
You must be signed in to change notification settings - Fork 43
MainDexList产生过程源码分析
cheyiliu edited this page Jul 8, 2016
·
1 revision
对于一个使用了MultiDex的Android工程,编译后在
/build/intermediates/multi-dex/{variant_path}/路径下面,
可以看到如下几个文件。
componentClasses.jar
components.flags
manifest_keep.txt
maindexlist.txt
这几个文件决定了主Dex中的该放哪些类。
通过分析componentClasses.jar和额外指定的Jar包includeInMainDexJarFile中的Class,
从allClassesJarFile中找出前面Class直接或间接引用到的Class,
然后加上manifest_keep.txt中keep住的类一起作为maindexlist.txt的内容。
将maindexlist.txt里的Class进行Dex操作就产生了classes.dex。
生成manifest_keep.txt的过程是:
遍历并解析/build/intermediates/manifests/full/{variant_path}/AndroidManifest.xml文件,
将其中application, activity, service, receiver, provider和instrumentation等
标签对应的组件类添加到manifest_keep.txt文件中。
因此manifest_keep.txt中的内容为AndroidManifest.xml中注册的
Application、四大组件、Instrumentation、BackupAgent和Annotation对应的类。
有心的同学可以去Android项目验证下是否确实如此。
manifest_keep.txt文件中的类是不能混淆的。
Just build something.