Incremental Upgrade Overview
The principle of incremental upgrade is very simple, that is, the application of the old version of the APK with the new version of the APK differential, to get updated parts of the patch, such as the old version of the APK has 20M, the new edition has 21M, the updated part may only be about 1 m, it should be explained that the resulting difference packet size is not simple subtraction Because of the need to include some context-sensitive things, the benefits of using differential upgrades are obvious, so you don't need to download the full 21M file, just download the update section, and the updated portion of the differential packet is small, which can greatly reduce the loss of traffic.
apk Incremental upgrade process
1. Generate a patch on the server.
2. Download patches to your phone.
3. Get a new install APK for an installed app with a patch.
4. Install the new version of the app and remove the old version and patch.
how to generate a differential packet
Bsdiff are typically used to make differential packets.
Bsdiff oldfile NewFile Patchfile
Differential packets are typically generated on the server side and then distributed to the client.
The source code is implemented in the C language.
Bsdiff Source
C code can be called in Java code via JNI to generate a differential packet
Bsdiff
How to synthesize a new upgrade package
The Bspatch command format is:
Android in the Data/app directory will have the original APK backup, with the original apk backup and server patch package can be used to synthesize the new apk. However, to be aware of version control, the patch package must be the final combination of the APK and the original APK differential packet. The original version is different, the upgraded version is different, the use of the differential packet is certainly not one.
Code Implementation
There is a good open source project on GitHub, and Smartappupdate has done a good job of encapsulating Bsdiff and Bspatch, which can be used directly.
Smartappupdate's GitHub Address
The improvement of Bsdiff
Bsdiff has been improved in Google Chrome projects
Code implementation Address:
Https://chromium.googlesource.com/chromium/src/courgette/+/master
Data comparison
Here is the sizes in bytes for the recent 190.1->190.4 update on the developer Channel:full update 10,385,920BSDIF F Update 704,512courgette update 78,848
lack of incremental upgrade
An incremental upgrade is not a perfect upgrade method, at least two points below:
1. Incremental upgrade is based on the differences between the two application versions to generate patches, you can not guarantee the user every time to upgrade to the latest, so you must be the release of each version and the latest version of the differential, so that all versions of the user can be differential upgrade, so that the operation of the original whole package upgrade is more cumbersome, However, it can be generated in batches with automated scripts.
2. The success of the incremental upgrade is based on the premise that the user's mobile phone must have an APK that allows you to copy it and use the same version as your server for the differential, so that it exists, for example, that the system's built-in APK cannot be acquired, cannot be incrementally upgraded, and that the content has been modified ( such as the cracked version of the APK), this is not an incremental upgrade, in order to prevent the composite patch error, it is best to pre-patch the old version of the apk before the Sha1sum check, to ensure the consistency of the base package.
Welcome to scan QR Code, follow the public number
Android Differential upgrade principle and implementation method