With the Android ecosystem and technology becoming more and more mature, many Android projects in the current market are very large, with a large number of teams, and many component-based plug-in technologies are gradually derived.

At the same time, because the Android installation package APK is also gradually increasing, each release, users update APK environment is complex, if the full update to download APK under the use of traffic, the network environment is bad, and so on, for the user experience is very bad.

Let’s start with a couple of concepts

Componentization: The common module code, extract lib project or JAR to achieve the effect of reuse.

Pluginization: The goal is to treat the modules or functions that need to be implemented as a separate extraction, reducing the size of the host and loading the modules when the functionality needs to be used. Involves dynamic proxies, classloaders, and the loading of another APK resource. For example: the 360 DroidPlugin (recommended)

Hotfix: Usually from the point of view of fixing bugs, it emphasizes fixing known bugs without the need for secondary installation of the application (involving keywords: Hook technology, dynamic proxy, etc.). For example: Ari AndFix.

Incremental update: APK incremental update is a technology used by many big apps. Bsdiff library patch file download and old version of APK synthesis to generate new APK principle (ligBspatch.so). Mobile game app incremental update is used more frequently. For example: SmartAppUpdates


Bsdiff generate patch -> Bzip2 compress -> Android download patch -> Bzip2 decompress Patch -> BSPatch merge patch -> new APK

Bsdiff is not specifically designed for incremental APK updates, and it can differential and merge any binary file.

Bzip2 uses Huffman coding to lossless compress files (compress subpackages for network transmission) and decompress them.

Process:

  • On the server side, generate the difference between the two versions of APK;
  • On the mobile client, use the installed APK and this subcontractor to synthesize the new version of APK;
  • Check whether the newly synthesized APK file is complete and whether MD5 or SHA1 is correct. If yes, guide the installation.

Common commands

Bsdiff To generate patch packages, run the bsdiff oldfile newfile patchfile command. For example, run the bsdiff xx_v1.0.apk xx_V2.0.apk xx.patch command

Bspatch To generate a new APK, run the bspatch oldfile newfile patchfile command. For example, run the bsdiff xx_v1.0.apk xx_v2.0.apk xx.patch command

use

Incremental Android update — BSDIFF&BSPatch

Disadvantages:

Incremental upgrade is not a perfect upgrade. It has at least two disadvantages:

  • Incremental upgrade is generated by the difference between the two application version patch, you can’t guarantee every time the user upgrade to the latest in time, so you must be issued to you each version and the latest version of the difference, so that all versions of the user can difference to upgrade, so operation compared with the original whole package upgrade is more tedious, However, it can be batch generated through automated scripts.

  • For an incremental upgrade to be successful, the user must have an APK on the phone that you can copy and that is consistent with the version of your server used for the difference, so that it exists. For example, the system’s built-in APK is not available and the incremental upgrade cannot be performed. For some versions that are consistent with your differential version but have been modified (such as cracked VERSION APK), it is also impossible to carry out incremental upgrade. In order to prevent synthetic patch errors, it is better to use MD5 or other methods to verify the integrity of patch packages.