Andfix for thermal repair function

Source: Internet
Author: User

Reference: http://blog.csdn.net/qxs965266509/article/details/49802429

http://blog.csdn.net/yaya_soft/article/details/50460102

Http://www.jianshu.com/p/479b8c7ec3e3

http://blog.hwangjr.com/2016/03/02/Android-HotFix%E6%96%B9%E6%A1%88/

With the constant urgency of development needs, open source has emerged a lot of hot fix project, but from the scheme, mainly based on rovo89/xposed alibaba/dexposed; method hooks, andfix from field ; Dex Sub-package Nuwa. There are many different implementations of the same principle, and this is no longer burdensome. These three implementation principles are very different, each has its own merits and demerits, let us approach these several programs.

This article only implements the Andfix to realize the thermal repair function

1. Add Dependencies First

compile ' com.alipay.euler:andfix:[email protected] '

2. Then initialize the Andfix (custom baseapplication, inherit application) in the application OnCreate method  

 Public classBaseapplicationextendsApplication {PrivateString appversion; PrivatePatchmanager Patchmanager; Private Static FinalString Apatch_path = "/out.apatch"; PrivateString Patchfile; @Override Public voidonCreate () {Super. OnCreate (); Try{appversion=Getapplicationcontext (). Getpackagemanager (). Getpackageinfo (Getpackagename (),0). Versionname; } Catch(packagemanager.namenotfoundexception e) {e.printstacktrace (); }          //Initializing patch Management classesPatchmanager =NewPatchmanager ( This); //initializing a patch versionPatchmanager.init (appversion); //load patches that have been added to the PatchmanagerPatchmanager.loadpatch (); Try {              //Get path automatically//patchfile = environment.getexternalstoragedirectory ()//. GetAbsolutePath (). Concat (Apatch_path); //temporarily write fixed path, test withPatchfile = "/sdcard" +Apatch_path; //Add to PatchPatchmanager.addpatch (Patchfile); } Catch(IOException e) {e.printstacktrace (); }      }   }       

3. Call the Addpatch method to load the new patch where needed, such as the 2nd step, such as calling this method after downloading the patch file.

4. Modify the bug in the place, respectively, the APK package, named old.apk,new.apk as follows:    

 Public class extends appcompatactivity {    private  TextView Mtextview;    @Override    protectedvoid  onCreate (Bundle savedinstancestate) {          Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_main);         = (TextView) Findviewbyid (R.id.textview);        Mtextview.settext (r.string.old_name);    }}

At this point the word "This is the old app" is displayed TextView, and a package is changed to name old.apk.

Change mainactivity to: Public    class Mainactivity extends Appcompatactivity {    private TextView mtextview;    @Override    protected void onCreate (Bundle savedinstancestate) {        super.oncreate (savedinstancestate);        Setcontentview (r.layout.activity_main);        Mtextview = (TextView) Findviewbyid (R.id.textview);        Mtextview.settext (r.string.new_name);    }}

  

At this point TextView display the word "This is the And_fix app", hit a package, change the name of new.apk.

5. The key step is to generate the Apatch file, which is the patch file, using the apkpatch-1.0.3 tool, This step, the fourth step to generate the two apk and signature files to be placed in the same folder Apkpatch Down,

Then run the command at the terminal: if it is already located in this directory, otherwise it will be reported commond not found

./apkpatch.sh-f new.apk-t Old.apk-o./-K andfix.jks-p 1q2w3e4r-a 123456-e 1q2w3e4r

Description

-F <new.apk>: New version

-T <old.apk>: older versions

-o <output>: Output directory

-K <keystore>: KeyStore used for packaging

-P <password>: keystore password

-a <alias>: KeyStore user Alias

-e <alias password>: KeyStore user alias password

When you are finished running the command:

Change the name of the file with the suffix. Apatch to Out.apatch, then copy to the root of the SD in the phone, reinstall OLD.APK, and you will see the page as follows:

Attention!! Prerequisites to register the relevant permissions in the manifest

<!--Create and delete files in SDcard permissions--

<uses-permission android:name= "Android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>

<!--write data to sdcard permissions--

<uses-permission android:name= "Android.permission.WRITE_EXTERNAL_STORAGE"/>

Andfix for thermal repair function

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.