搭建本地 Server 模拟下载补丁的使用案例参请考 AndFixUage
AndFix is a solution to fix the bugs online instead of redistributing Android App. It is distributed as Android Library.
Andfix is an acronym for “And**roid hot-**fix“.
AndFix supports Android version from 2.3 to 6.0, both ARM and X86 architecture, both Dalvik and ART runtime.
The compressed file format of AndFix’s patch is .apatch. It is dispatched from your own server to client to fix your App’s bugs.
The implementation principle of AndFix is method body’s replacing,
AndFix judges the methods should be replaced by java custom annotation and replaces it by hooking it. AndFix has a native method art_replaceMethod
in ART or dalvik_replaceMethod
in X86 architecture. Implementations are different. For Dalvik, it will change the target method type to ‘native’ and link the method implementation to AndFix’s own native, generic method called dalvik_dispatcher
, this method then takes care of invoking callbacks that have been registered, as we say ‘hooked’. For ART, we just change the ArtMethod
properties of itself to replace it.
For more details, here.
Directly add AndFix aar to your project as compile libraries.
For your maven dependency,
```
com.alipay.euler
andfix
0.3.1
aar
```
For your 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,
patchManager.loadPatch();
You should load patch as early as possible, generally, in the initialization phase of your application(such as Application.onCreate()
).
Add patch,
patchManager.addPatch(path);//path of the patch file that was downloaded
When a new patch file has been downloaded, it will become effective immediately by addPatch
.
AndFix provides a patch-making tool called apkpatch.
The apkpatch
tool can be found here.
Prepare two android packages, one is the online package, the other one is the package after you fix bugs by coding.
Generate .apatch
file by providing the two package,
usage: apkpatch -f -t -o
Now you get the application savior, the patch file. Then you need to dispatch it to your client in some way, push or pull.
Sometimes, your team members may fix each other’s bugs, and generate not only one .apatch
. For this situation, you can
merge .apatch
files using this tool,
usage: apkpatch -m -o
If you enable ProGuard, you must save the mapping.txt, so your new version’s build can use it with “-applymapping”.
And it is necessary to keep classes as follow,
Native method
com.alipay.euler.andfix.AndFix
Annotation
com.alipay.euler.andfix.annotation.MethodReplace
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.
```
-keep class * extends java.lang.annotation.Annotation
-keepclasseswithmembernames class * {
native ;
}
```
If you use it, such as Bangcle. To generate patch file, you’d better to use raw apk.
The following is important but out of AndFix’s range.
The libraries javadoc can be found here.
…
Apache License, Version 2.0
Copyright (c) 2015, alipay.com