What is thermal repair technology? AndFix Framework replacement principles and Advantages…
What is thermal repair technology?
When an urgent Bug that seriously affects users appears in our online app, it is usually necessary to fix the Bug offline at the first time. After a series of tests and verification, an upgraded version is finally released in major application markets through channel packages. Users can download a new package to fix the Bug.
Obviously, the whole process is time-consuming and labor-intensive, and to some extent will affect the user experience. In view of this problem, the hot repair framework was created. Developers only need to release patches for bugs and push them to users. When users detect the patches, they automatically pull them and fix bugs.
For Bug handling, we should not rely too much on the hotfix framework. In the development process, we should do a good job of self-testing according to the standard process and cooperate with the testers to complete the test process.
Principles and advantages of AndFix
-
AndFix, which stands for Android Hot-fix. Android hotpatch is an Android hotpatch framework that allows apps to fix online bugs without re-releasing the version.
-
AndFix is all about method replacement, replacing buggy methods with methods in patch files
Andfix uses a process introduction in the project
1. The patch package is generated
1. Normal compilation package generates APK files (with bugs), such as old.apk; 2. After fixing bugs, package and generate new APK files, for example, new.apk. 3. Use the apkPatch tool in the Tools folder to generate. Aptch patch files.Copy the code
(a). cdGo to the Tools folderCopy the code
(b). Perform apkpatch-f <new> -t <old> -o <output> -k <keystore> -p <***> -a <alias> -e< * * * >Copy the code
-o <output> : indicates the output directory. -k <keystore> : indicates the keystore used for packaging. -p <password> : indicates the keystore password-a <alias> : keystore user alias-e <aliasPassword > : keystore alias password-f<new.apk> : new version -t <old.apk> : old versionCopy the code
2. Upload the patch file
Manually upload the generated. Apkpatch file to the server (details are not available yet)
3. Download the patch file
1. Check the patch package interface.Copy the code
Request interface during program initialization to detect server patch information
No patch: continue to initialize the frame <div class="md-section-divider"></div>Copy the code
If there is a patch, perform the following 2 operationsCopy the code
2. Patch package download interface;Copy the code
Downloading patch Files
Pull failed: next program to re-check the patch package, and downloadCopy the code
If the vm is successfully pulled, perform the following operations: 1Copy the code
3. Decompress;Copy the code
1. Decompress the compressed packageCopy the code
2. Validity verification (file type, length, signature verification of patch file, fingerprint verification of optimization file, etc.)Copy the code
4. Decryption;Copy the code
Decrypt compressed packageCopy the code
AddPatch patchmanager.addpatch (path)Copy the code
4. Restart the program, load patches, and fix bugs
Patchmanager.loadpatch ()Copy the code
Patches are usually loaded during the initialization phase of the Application (e.g. Application.oncreate ());
Internal patch replacement process:
Download the patch to the corresponding directory. 2. Load 3 using the loadPatch method. The patch will be copied to the app directory, and the downloaded patch file will be deleted. 4. If versionName changes, all patches in apatch will be removed.Copy the code
5. Confusion handling
– printMapping proguard.map You need to generate the mapping file to record the confusion rule. Then you can comment out printmapping and use applymapping only.
- Applymapping proguard.map (then add below)Copy the code
-keepclass*extendsjava.lang.annotation.Annotation Copy the code
-keepclasseswithmembernamesclass*{native ; }Copy the code
-keepclasscom.alipay.euler.andfix.**{ *; } Copy the code
6. Limitations
-
New classes and fields cannot be added
-
The constructor and Application’s onCreate method cannot be replaced
-
New function modules cannot be added dynamically, which is different from the replacement of DEX