-
Hot repair is mainly used to repair code, fix bugs, add independent functions, his principle is mainly to operate PathClassLoader, DexClassLoader.
-
The PathClassLoader is a classloader, and DexClassLoader can load classes.dex files from inside.jar and.apk files. They’re all subclasses of Classloder.
-
What is classloder? Unlike normal programs, Java programs (class files) are not native executable programs. When running a Java program, the JVM (Java Virtual Machine) is first run, and then the Java class file is loaded into the JVM. The part responsible for loading the Java class is called the Class Loader.
-
A ClassLoader can contain multiple dex files, each of which is an Element. The dex files are arranged into an ordered array of dexElements. When searching for classes, the dex files will be traversed in sequence, and then the class will be searched from the currently traversed dex file. If you cannot find it, proceed to the next dex file.
-
In this case, we can do something in the dexElements, such as place our patch.jar containing the fixed classes in the first element of the array, so that when we traverse findClass, the fixed classes will be found and replaced by the buggy classes.
-
The principle is simply to use the ClassLoader to load dynamically when opened, and then use the reflection mechanism to call the classes and methods in the plug-in, generally with a set of plug-in framework to cooperate with the use.
Principle:
Method replacement, replace the buggy method with the method in the patch file.
Review images
Review images
Advantages:
Critical bugs requiring urgent fixes Bugs that can be fixed in the next iteration affect the behavior of the user experience
Don’t need to restart
Disadvantages:
- Can’t add new classes (or inner classes) and new fields, new methods? I tried it myself
- informationThe source file cannot be replacedI tried to change the original picture, but the new one did not work
- Cannot modify the XML layout file no
- The hardened package patch cannot be used. If hardening is required, the original package is needed to generate the patch, but the generated patch is also easy to crack
- You can’t fix the same method twice, otherwise your App won’t work at all
- Change the names of loaded patch files. If the names overlap, they will not be loaded again
Review images
Timing of patch loading:
It can be placed in the onCreate method of a custom Application, in the button click event, or in a broadcast that listens for network changes.
Operation:
-a,--alias keystore entry alias.
-e,--epassword <***> keystore entry password.
-f,--from new Apk file path.
-k,--keystore keystore path.
-n,--name patch name.
-o,--out
output dir.
-p,--kpassword <***> keystore password.
-t,--to old Apk file path.Copy the code
Ali bacc the
www.tuicool.com/articles/vi…
The main benefit is that patches can be managed well, such as stop release, continue release, release rollback, and so on
Review images