What hot fix?
It means that the released APP has found a bug and needs to be repaired (resource repair, code repair, so library repair), but do not want to re-release the installation package, and solve it by letting users download the patch file.
Advantages of hot repair
No need to re-release the installation package; users have no perception of repair, no need to download the latest applications, saving user traffic; the repair success rate is high, avoiding business losses caused by online bugs, and minimizing losses.
Shortcomings in hot repair
All hot fix frameworks cannot guarantee 100% repair success. It can only be said that bug fixes are relative. The four hot fix frameworks in the following figure have their own strengths and weaknesses:
For example, Ali's AndFix does not support the replacement of resource files (including xml layouts, images, manifest files, etc.), lib replacement, class replacement, new classes, new methods, and only bugs in the code. replace!
There is a common problem in the hot fix framework: Although bugs can be fixed without installing a new version of the installation package, if the locally downloaded patch package is deleted, the previous bug will be renewed!
Because the hot fix is not to combine to generate a new apk, but to dynamically load the part of the code that fixes the bug.
In other words, the code to fix the bug is stored in the patch package. Delete the patch package, the code to fix the bug will no longer exist, and the previous bug will be rebuilt.
The mainstream hot repair framework currently on the market:
In the above picture, the cold start repair is to synthesize a brand new dex file to replace the original dex file (the dex file contains all app codes). Its function is to break through the limitation that the hot replacement scheme cannot add new class methods, and can better achieve Repair purpose.
The following demonstrates the steps of Alibaba's AndFix integration:
1. Add dependency in Module's build.gradle (as shown below)
2. Integrate the code in Application:
3. Kill the process in the onDestroy() method of MainActivity
How to generate patch files for mobile download
1. Open the link: https://github.com/alibaba/AndFix , download the patch creation tool of apkpatch, and unzip it locally
2. Prepare two software packages and a signature file keystore (for example: release-key.keystore), one for the online problematic software package (for example: bug.apk), and the other for fixing the bug (for example: fix.apk), and put it in the directory just decompressed. As shown below:
3. Open the Windows command line tool, enter the decompression directory, enter apkpatch.bat -f fix.apk -t bug.apk -o output -k release-key.keystore -p 123456 -a zhibin -e 000111 , and then press Enter You can see the picture below:
(ps: 123456 is the keystore password of the signature file, zhibin is the alias of the signature file, and 000111 is the alias password. The generated patch file is in the output folder, renamed to fixbug.apatch and moved to the same layer for easy screenshots)
At this point, Alibaba's AndFix hot fix framework has been integrated, fixbug.apatch is uploaded to the server for download on the mobile terminal, and the hot fix function can be tested!
Today's sharing is over, goodbye~