AndFix is a library that offer hot-fix for Android App. It could help Android developer to fix App bugs online. Andfix is an acronym for "Android hot-fix".
AndFix supports Android 2.3 to 6.0, arm and x86 architecture, dalvik runtime and art runtime.
AndFix's patch is .apatch file.
The implementation principle of AndFix is method's body replace :
bug fix process:
-
directly add AndFix aar to your project as compile libraries.
-
maven dependency:
<dependency> <groupId>com.alipay.euler</groupId> <artifactId>andfix</artifactId> <version>0.3.1</version> <type>aar</type> </dependency>
or gradle dependency:
```
dependencies {
compile 'com.alipay.euler:andfix:0.3.1@aar'
}
```
-
initialize PatchManager:
patchManager = new PatchManager(context); patchManager.init(appversion);//current version
-
load patch. load patch as early as possible, generally, at the initialization phase of your app (such as application.oncreate()):
patchManager.loadPatch();
-
add patch. when new patch file has be downloaded,the patch will become effective immediately by add.
patchManager.addPatch(path);//path of the patch file that be downloaded
To ensure that these classes can be found after running an obfuscation and static analysis tool like ProGuard add the configuration below to your ProGuard configuration file.
-
native method
com.euler.cloudfix.CloudFix
-
annotation
com.euler.cloudfix.annotation.MethodReplace
-keep class * extends java.lang.annotation.Annotation -keepclasseswithmembernames class * { native <methods>; }
The patch make tool is apkpatch.
Apkpatch can be found here
- generate .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 files:
usage: apkpatch -m <apatch_path...> -o <output> -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.
- import samples/AndFixDemo to your IDE, set AndFixDemo depend on AndFix(library project or aar).
- build project, save the package as 1.apk, and then install on device/emulator.
- modify com.euler.test.A, references com.euler.test.Fix.
- build project, save the package as 2.apk.
- use apkpatch to make a patch.
- rename the patch file to out.apatch, and then copy it onto sdcard.
- run 1.apk,view logcat.
The libraries javadoc can be found here
- verify the signature of patch file
- verify the fingerprint of optimize file
...
Copyright (c) 2015, alipay.com