Android apk Incremental Update

Source: Internet
Author: User

Objective

There are many more techniques for apk updates, such as: Incremental update, plug-in development, hot fix, RN, silent installation.

Here's a quick introduction:

What is an incremental update?

Incremental updates are the only places where the original app is updated and the rest remains intact.

The benefits of this are obvious compared to the fact that each update will download the full APK package: There are always fewer places to change, so the volume of the update package is much smaller.

Process for incremental Updates

1.APP detection of the latest version: The current version to tell the server, the service side to judge.

If there is a new version, the server needs to make a difference between the current version of the APK and the latest version of the APK, resulting in a patch differential file. (or the new version of the APK uploaded to the server when the difference is good)

2.APP in the background to download the differential file, the file MD5 check, the local merge (with the local data directory under the apk file merge), after merging the latest apk, prompting the user to install.

3. The ultimate goal of incremental updates: Save traffic to update the host APK.

The trouble with differential processing is the difference between different application market channels and many different versions.

Note: The new version is likely to be smaller than the old version, and the difference simply records the changed parts.

Server-side behavior (background engineer operation)

1. Download the third-party libraries to use for splitting and merging (Bsdiff, bzip2)

The third-party libraries we use are: Binary diff, abbreviated as Bsdiff, which is specifically designed to achieve the differential and merging of files, and its official website is as follows:

http://www.daemonology.net/bsdiff/

Here we can click "Here" to download the source code, this is the Linux source code. You can also download the Windows version of the source code, click "Windows Port".

Recommend compiling with SBSDIFF4.3-WIN32-SRC under Windows

This library refers to the BZIP2 library, the official website is as follows:

http://www.bzip.org/

2. Compiling third-party library source code generation DLL Dynamic Library

In order to facilitate the demonstration, I am in the Windows 10 platform to compile with VS2017, the actual situation of the server is mostly running under the Linux system, this everyone to test it.

Windows Build DLL Dynamic Library Reference Android NDK Development Tour 10--JNI--JNI development process

Resources used

Note: The com_haocai_bsdiff_bsdiff.h is based on the Java file declaration, and the steps are omitted.

The following error message will be found during compilation

Character Set issues

Unsafe and outdated functions are used.

SDL Check does not pass

Here are the workarounds:

Configuring character Sets

Ignore unsafe and outdated function warnings

Set up SDL Check form

In addition, may not be found in the header file errors, this may be a coding problem, because the foreign use of the Apple Computer with the Windows computer compiled inconsistent results. The transcoding function can be notepad++ by transcoding, all to UTF-8 no BOM format encoding can, Windows, Linux Universal.

Inside the build configuration of our project properties select the DLL, and modify the solution for your computer's corresponding platform, then compile, generate DLL dynamic library file.

3.Java code calls

Create a Web project to use as the service side of the app. The Create tool class is specifically designed to generate differential packets:

Where JNI is implemented as follows (the implementation is written in bsdiff.cpp):

By studying the source code of Bsdiff, we found that the main function inside the bsdiff.cpp is the entry function, avoid ambiguity to change the function name main to Bsdiff_main, and then through the JNI to invoke.

According to the Bsdiff_main function method in Bsdiff.cpp, there are the following key statements

if (argc! = 4) Errx (1, "Usage:%s oldfile newfile patchfile\n", argv[0]);

You need to pass in 4 parameters as prompted:

Argv[0] = "Bsdiff";//This parameter is useless

ARGV[1] = oldpath;//old apk file path

ARGV[2] = newpath;/new apk file path

ARGV[3] = patchpath;//apk differential file path

Then we prepare two apk files, different versions of the best Java code, the resources are not the same.

Write a Java test class to generate the differential packet:

The build results are as follows:

Apk.patch for the generated differential packet

Attention:

TEST_NEW.APK, test_old.apk should be placed in the target directory first

The program method for generating the differential packets in the Bsdiff.cpp is asynchronous, so it might be a bit of a wait to generate the complete apk.patch. Apk.patch volume size stops growing, indicating the end of the build.

4. Simple background javaweb for Android front-end download Apk.patch differential packet

Reference Intellij idea Create javaweb and servlet simple implementation

Enter in the browser

Http://localhost:8080/App_Update_Web/patchfile/apk.patch

, prompting to download

Server Setup is complete.

Android Client Behavior

1. Compiling third-party libraries for merging (Bsdiff, bzip2)

The corresponding Java code is as follows:

On the Android side, we need to copy the bzip2 and Bsdiff files into the JNI directory, so we just need to compile a bspatch.c source file.

Files required by the Ndk-build

Since Android phones are inherently Linux systems, we use Bsdiff's Linux version of the library directly.

As with the server side, here we change the main function in bspatch.c to Bspatch_main, which provides the JNI call:

The Code v1.0 differential packet Merge core code is as follows:

Main logic in the FileDownload method, we first download the differential packet, then the local composition, and finally prompt the user to install.

In order to achieve the obvious effect, two versions can delete some resource files, modify Java code, layout files and so on.

Note: There may be a problem here 7.0, exposing the path to other apps, need to fileprovider to achieve (not difficult, this left to everyone to do it).

SOURCE Download: https://github.com/kpioneer123/DiffInstallApp

Android apk Incremental Update

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.