The concept of App hot FIX:
The app fix is defined for bug scenes in the Fix app. When we have a bug in our online app, we want to fix the bug without the user's knowledge, then we'll use a hot fix.
The implementation principle of app hot fix:
First, generate a new version of the APK with the old version of the APK's diff patch package file;
Second, use the hot Fix framework API to attempt to load the patch diff package for the specified path in application;
Finally, you just need to put the patch difference package baby to the corresponding path, to replace the bug app, when the applcation is created, the patch file is loaded into memory and the corresponding method is replaced.
Commonly used heat repair framework---Ali's andfix
Steps to use:
First, rely on the Andfix class library in the Gradle file, and write the code that loads the patch file in the application OnCreate method:
// after repeated testing, the 0.5 version is less stable than the 0.4 version, so we use a stable version // compile ' com.alipay.euler:andfix:[email protected] 'compile ' com.alipay.euler:andfix:[email protected] '
Add the code to load the patch file:
Public classMyAppextendsApplication {@Override Public voidonCreate () {Super. OnCreate (); Patchmanager Patchmanager=NewPatchmanager ( This); String appversion= "1.0";//version number of the current appPatchmanager.init (appversion);? //start loading patch filesPatchmanager.loadpatch ();? File Patchfile=NewFile (Environment.getexternalstoragedirectory (), "Out.apatch"); Try { if(Patchfile.exists ()) {//specify the path to the patch filePatchmanager.addpatch (Patchfile.getabsolutepath ()); } } Catch(IOException e) {e.printstacktrace (); } }}
We copy the 2 apk and signature files together into the andfix-master\tools\apkpatch-1.0.3 directory and use the Apkpatch command to generate a patch file with the following command:
Apkpatch-f fix.apk-t bug.apk-o bug_fix-k test.jks-p 111111-a test-e 111111
Place the patch file under the specified path, run the app with the bug, restart application, and automatically overwrite the original code with the bug.
Note: It is not necessary to worry that the patch file will be mistakenly deleted by the user because the patch file has been copied to the app's package.
Hot fixes are only for bug-level fixes, and Ali's andfix is just for the repair of the method and cannot be repaired on the four components of the class and Android. And the heat repair is unstable and does not fit all the phones.
App Hot fixes