Can I fix bugs online without releasing Android? -- AndFix framework, androidandfix
The geese are in groups, and the e will fly forever
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:
<dependency> <groupId>com.alipay.euler</groupId> <artifactId>andfix</artifactId> <version>0.3.0</version> <type>aar</type></dependency>
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:
com.euler.cloudfix.CloudFix
com.euler.cloudfix.annotation.MethodReplace-keep class * extends java.lang.annotation.Annotation-keepclasseswithmembernames class * { native <methods>;}
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 <new> -t <old> -o <output> -k <keystore> -p <***> -a <alias> -e <***> -a,--alias <alias> alias. -e,--epassword <***> entry password. -f,--from <loc> new Apk file path. -k,--keystore <loc> keystore path. -n,--name <name> patch name. -o,--out <dir> output dir. -p,--kpassword <***> keystore password. -t,--to <loc> old Apk file path.
Merge. apatch File
usage: apkpatch -m <apatch_path...> -k <keystore> -p <***> -a <alias> -e <***> -a,--alias <alias> alias. -e,--epassword <***> entry password. -k,--keystore <loc> keystore path. -m,--merge <loc...> path of .apatch files. -n,--name <name> patch name. -o,--out <dir> output dir. -p,--kpassword <***> keystore password.
Run sample
/*
* @ Author zhoushengtao (Zhou Shengtao)
* @ Since 15:23:00, January 1, September 15, 2015
* @ Weixin stchou_zst
* @ Blog http://blog.csdn.net/yzzst
* @ Exchange and learning QQ group: 341989536
* @ Private QQ: 445914891
/
Copyright Disclaimer: Reprint Please note: http://blog.csdn.net/yzzst. This article is the original article of the blogger and cannot be reproduced without the consent of the blogger.