Android hotfix: android hotfix

Source: Internet
Author: User

Android hotfix: android hotfix

1.1 Basic Introduction
 
Let's go to github and learn about its https://github.com/alibaba/AndFix.

Here is a concept. The AndFix. apatch patch is used to fix the problem. Let's see how it is implemented.

  
1.2 generate an apatch package
  
. At this time, we can use the tools provided by Alibaba github to generate a xxxx. apatch package for fixing bugs.

Command:Apkpatch. bat-f <new>-t <old>-o <output>-k <keystore>-p <>-A <alias>-e <>

-F: New apk version without bugs
-T: Old apk with bugs
-O: the folder where the patch file is generated
-K: Signature packaging key
-P: Signature and packaging key and password
-A: signature key alias
-E: sign the alias password (which is generally the same as the key password)

My website is like this:

Apkpatch. bat-f new.apk-t old.apk-o out-k joke. jks-p 240336124-a connotation section-e 240336124

Patch generated:

 

 

1.3 repair apatch package

How can I get the apatch package? We must request the API to download our repaired apatch package. Of course, it may be great if it is not. After downloading it, we can call the method to fix it. We can temporarily test it locally. These codes must be written before:

Public class BaseApplication extends Application {// Patch Management class public static PatchManager mPatchManager; @ Override public void onCreate () {super. onCreate (); // capture the crash information ExceptionCrashHandler. getInstance (). init (this); // Ali hotfix try {mPatchManager = new PatchManager (this); // initialize the patch version String pkName = this. getPackageName (); String versionName = getPackageManager (). getPackageInfo (pkName, 0 ). versionName; // initialize the version name mPatchManager. init (versionName); // load the previous patch mPatchManager. loadPatch ();} catch (PackageManager. nameNotFoundException e) {e. printStackTrace ();}}}
MainActivity on the home page
1 public class MainActivity extends BaseSkinActivity {2 3 @ Override 4 protected void initData () {5 // obtain the last crash Message 6 File crashFile = ExceptionCrashHandler. getInstance (). getCrashFile (); 7 // upload the file to the server ....... 8} 9 10 @ Override11 protected void initView () {12 13} 14 15 @ Override16 protected void setContentView () {17 setContentView (R. layout. activity_main); 18} 19 20 @ Override21 protected void initTitle () {22 23} 24 25 @ Onclick (R. id. test) 26 public void test (View view) {27 // an exception will be reported 28 Toast. makeText (this, Utils. test (), Toast. LENGTH_LONG ). show (); 29} 30 31 @ Onclick (R. id. ali_fix) 32 public void aliHotFix (View view) {33 try {34 // The test is currently in local 35 String patchFileString = Environment. getExternalStorageDirectory () + "/fix. apatch "; 36 Log. e ("TAG", patchFileString); 37 // fix apatch. It takes effect immediately without restarting. mPatchManager. addPatch (patchFileString); 39 Toast. makeText (this, "Bug fixed successfully", Toast. LENGTH_LONG ). show (); 40} catch (Exception e) {41 e. printStackTrace (); 42 Toast. makeText (this, "Bug fixing failed", Toast. LENGTH_LONG ). show (); 43} 44} 45}

The running effect is at the top. If you click test directly, an exception will be thrown back. After you click Alibaba open source Hotfix, click test again and you will find that the test will not crash. You may not understand the following content. Please be prepared.

 

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.