Thermal remediation techniques are divided into several parts:
Principle Introduction
Android Hotfix Source Analysis
Custom Frames
1.Android Sub-Package Multidex principle
First, what's Dex?
Dex is the EXE file in window which is an executable problem.
Android does not use a traditional Java virtual machine, but instead uses a Dalvik virtual machine. When the APK is installed on the phone, Dalvik will first convert the de file to the Odex file,
Optimize the structure.
In an earlier Android system, in order to optimize Dex, all the method will be stored in a table, the size of the table short, that is 65535 (65K)
But now Android code is very much, more than 65K is normal, this time need a solution to solve this problem.
The simple thing is to split the compiled class file into 2 Dex files, bypassing the 65k limit.
For specific implementations of subcontracting, you can refer to the Dex Subcontracting Scheme Overview and the configuration of the Multidex package using
2.Android Hot Patch Repair Technology principle
Purpose: Sometimes we need to change a few lines of code, but we need to resend each market, re-release and so on. Is it possible to solve this problem simply by hitting patch?
First look at the Dex loaded source code:
PublicClass 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) { returnClazz; } } } if(Dexelementssuppressedexceptions! =NULL) {Suppressed.addall (Arrays.aslist (dexelementssuppressedexceptions)); } return NULL;}
Each element corresponds to the Dex file, so the load class is to find the corresponding code from the Dex file. But, you can find that once you have found a successful, you return directly.
That is, if 2 Dex contains the same class, the previous one will be returned first.
So our solution comes, using a new Dex, let him at the very front of the element file table so that our modified class file will be loaded first.
In theory, if the same class exists in different Dex, then the class that precedes the Dex file is preferred, such as:
Based on this, we envision a hot patch scenario, package the problematic class into a Dex (Patch.dex), and then insert the Dex into the front of the elements, such as:
Well, the solution is based on the second solution of the split Dex, the implementation of the scheme if you understand the principle of the split Dex, you should quickly implement the program, if you do not split the DEX project, you can refer to Google's Multidex scheme implementation. Then, when inserting the array, insert the patch into the front.
But we found that after inserting the Patch.dex, the error is due to class_ispreverified. What is this stuff?
The class that is directly referenced in the method of the class, if in the same Dex, will be marked with class_ispreverified.
We individually package a antilazyload class into Hack.dex so that each class is called. We add in the constructor:
Public class a{ public A () { system.println (antilazyload. class ); }}
So, a refers to a class that is not in a Dex, so that it does not get class_ispreverified code. And then there is no problem.
Reference:
Introduction to the hot patch dynamic repair technology for Android app
http://my.oschina.net/853294317/blog/308583
http://blog.csdn.net/lmj623565791/article/details/49883661
Android Hot Fix technology (1)---principle