Hot fixes in Android

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.

Insert picture description here

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:

Insert picture description here

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:

Insert picture description here

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)
Insert picture description here

2. Integrate the code in Application:

Insert picture description here

3. Kill the process in the onDestroy() method of MainActivity

Insert picture description here

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:

Insert picture description here

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:

Insert picture description here

(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~

Guess you like

Origin blog.csdn.net/yanhuomatou2015/article/details/109089413