Can I fix bugs online without releasing Android? -- AndFix framework

Source: Internet
Author: User

Can I fix bugs online without releasing Android? -- AndFix framework

 

I have introduced a framework named Alibaba dexposed, which can dynamically complete some patches online. However, because of its performance and compatibility (not supporting ART), many friends decided not to study this framework.

Today, I will introduce you to an Alibaba open-source framework, AndFix. Like Dexposed, this framework is designed for online patching. After a bug is detected, the tool library of the local logical code is repaired through online patches.

The principle is similar to Dexposed. Here we will not explain it in detail. If you are not clear about the shoes, you can read my other two articles:
Http://blog.csdn.net/yzzst/article/details/47954479
Http://blog.csdn.net/yzzst/article/details/47659987

If you want to ask me, why do alibaba internal teams have to do something similar?
I can only answer, if you have worked in a large company, you should know that there is a kind of sorrow-KPI.

AndFix Github address: https://github.com/alibaba/AndFix

How to use it?
The official documents translated by the author are as follows:

AndFix

AndFix is an online hot Patching framework for Android apps. With this framework, we can modify bugs in the App online without recurrence. AndFix is short for "Android Hot-Fix.

Currently, AndFix supports Android 2.3 to Android 6.0, and supports devices with arm and X86 system architectures. Perfect support for Dalvik and ART Runtime.

The AndFix patch file ends with. apatch.

AndFix Principle

The principle of AndFix is very simple. Is to replace existing methods in the project:

The following procedure logic is available for creating an online patch package:

Integrated Project usage

Directly add AndFix aar to the compilation dependency library in the project.

Maven dependency:


      
   
    com.alipay.euler
       andfix    
   
    0.3.0
       
   
    aar
   
  

Or Gradle dependency:

dependencies {    compile 'com.alipay.euler:andfix:0.3.0@aar'}
How to Use

1.Initialize PatchManager:

patchManager = new PatchManager(context);patchManager.init(appversion);//current version

2.Load patch package
The sooner the patch package is loaded, the better. Generally, we usually load the patch package in the onCreate method of the custom Application. That is:

patchManager.loadPatch();

3.Add patch package
Download the new patch package and call the addPatch method to add a patch. The patch takes effect immediately.

patchManager.addPatch(path);//path of the patch file that be downloaded
ProGuard obfuscation settings

Ensure that some class files are not obfuscated by proguard when used. Of course, the obfuscation configuration of proguard is as follows:

NATIVE method
com.euler.cloudfix.CloudFix
Annotation
com.euler.cloudfix.annotation.MethodReplace-keep class * extends java.lang.annotation.Annotation-keepclasseswithmembernames class * {    native 
  
   ;}
  
Development Tools

Don't think that the patch is just a direct development of an apk, and a specialized tool is required to make the patch. Here is a tool called apkpatch used to make AndFix patches.

Address: https://github.com/alibaba/AndFix/raw/master/tools/apkpatch.zip

How to use this tool

Generate a. apatch File

 usage: apkpatch -f 
  
    -t 
   
     -o
     -k 
     
       -p <***> -a  -e <***> -a,--alias      alias. -e,--epassword <***>   entry password. -f,--from 
      
        new Apk file path. -k,--keystore 
       
         keystore path. -n,--name 
        
          patch name. -o,--out 
        
       
      
     
   
  
Output dir.-p, -- kpassword <***> keystore password.-t, -- old Apk file path.

Merge. apatch File

 usage: apkpatch -m  -k 
  
    -p <***> -a  -e <***> -a,--alias      alias. -e,--epassword <***>   entry password. -k,--keystore 
   
        keystore path. -m,--merge 
    
         path of .apatch files. -n,--name 
     
             patch name. -o,--out 
     
    
   
  
Output dir.-p, -- kpassword <***> keystore password. Run sampleimport samples/AndFixDemo to your IDE. Setting AndFixDemo depends on AndFix (library project or aar ). The final result of the buildproject is 1.apk, And the apk is installed on the device. Modify com. euler. test. A and reference com. euler. test. Fix. Build project, save as 2.apk. Use the apkpatch tool to create a patch. Rename the patch file to out. apatch and copy the file to the SD card. Run 1.apk to view logcat.

 

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.