Concept of incremental update:
When the version of the app installed on our phone is inconsistent with the latest version of the server, the traditional practice is to re-download and install a new version of the APK file, but this is a way of consuming traffic that is not conducive to user experience. An incremental update downloads only the difference between the current app version and the latest version, and then merges the current version with the latest version and then installs it. Currently support incremental update of the application market has GooglePlay, 360 mobile phone market and so on.
How the incremental update works:
Use the Open Source Tool Bsdiff to compare binary files with the new apk and legacy apk, get patch files, and then use the Open Source Tool Bspatch to merge and reinstall the old apk and patch files. In actual development, we only need to write the native method, call. So file to implement the old version of the APK and patch file merge and installation, patch files are generated by the server side.
Code implementation of incremental update: Using Incremental update framework Smartappupdates
//load so library first Static{system.loadlibrary ("Apkpatchlibrary"); }? Public voiddownloadnewapk (view view) {//because it is a time-consuming operation, an asynchronous task is required NewAsynctask<void,void,integer>(){ //3. The new apk file path after compositingString Newapkpath = environment.getexternalstoragedirectory () + "/weibonew.apk"; @OverrideprotectedInteger doinbackground (Void ... params) {//1. Download the patch pack from the server firstFile Patchfile =Downloadpatchfile (); String Patchpath=Patchfile.getabsolutepath (); //2. Get the path to the current version of the APK fileString AppPath = "/data/app/com.sina.weibo-1.apk"; returnPatchutils.patch (Apppath,newapkpath,patchpath); }? @Overrideprotected voidonpostexecute (Integer integer) {Super. OnPostExecute (integer); if(integer==0){ //Explain that the composition was successful, then start the installationToast.maketext (mainactivity. This, "synthesized successfully! ", Toast.length_short). Show (); APKUTILS.INSTALLAPK (mainactivity. This, Newapkpath); }Else{toast.maketext (mainactivity). This, "Synthesis failed!", Toast.length_short). Show (); }}}.execute (); }? PrivateFile Downloadpatchfile () {return NewFile (Environment.getexternalstoragedirectory (), "Weibo.patch"); }
App Incremental Update