Dexclassloader loads a class that has no component life cycle, meaning that even if dexclassloader loads the component through dynamic loading of Dex, the load class fails when the system starts the component.
There are two ways to solve the problems that appear above:
Method One: http://blog.csdn.net/androidsecurity/article/details/8809542, change the classloader of the system to make it a custom loader.
Features: Two Dex has a distinct split line, the first Dex only starts, and the first Dex's class loading information is not followed by the so-called "shell-Up program".
Main points:
1.替换classloader:RefInvoke.setFieldOjbect("android.app.LoadedApk", "mClassLoader",wr.get(), dLoader);
2. Replace application:RefInvoke.setFieldOjbect("android.app.ActivityThread","mInitialApplication", currentActivityThread, app);
3.替换contentprovider RefInvoke.setFieldOjbect("android.content.ContentProvider","mContext", localProvider, app);
Method Two: Http://www.cnblogs.com/twlqx/p/4716026.html, the second Dex's class information is added to the first Dex's Pathclassloader element using a subcontracting method.
Features: Two DEX classes can be called each other, and in general, external Dex contains key hidden class information.
Main points:
1. Load external dex:
Dexclassloader Dexclassloader = new Dexclassloader (LibPath, Sapplication.getdir ("Dex", 0). GetAbsolutePath (), LibPath, Sapplication.getclassloader ());
2. Merge the element attribute of Pathclassloader and Dexclassloader and assign to the element of Pathclassloader
Object dexelements = Combinearray (getdexelements (Getpathlist (Pathclassloader)), Getdexelements (GetPathList ( (Dexclassloader)));
Object pathList = getpathlist (Pathclassloader);
SetField (PathList, Pathlist.getclass (), "dexelements", dexelements);
Two ways to dynamically load Dex