
热补丁方案有很多,其中比较出名的有腾讯Tinker、阿里的AndFix、美团的Robust以及QZone的超级补丁方案。
一、AndFix
在native动态替换java层的方法,通过native层hook java层的代码。


特点是:即时生效。
使用到的技术有:注解、NDK。
github地址:https://github.com/alibaba/AndFix
二、Robust
对每个函数都在编译打包阶段自动的插入了一段代码。类似于代理,将方法执行的代码重定向到其他方法中。


原理:https://tech.meituan.com/2016/09/14/android-robust.html
特点是:即时生效。
使用到的技术有:注解、插桩、代理。
github地址:https://github.com/Meituan-Dianping/Robust
三、Tinker
Tinker通过计算对比指定的Base Apk中的dex与修改后的Apk中的dex的区别,补丁包中的内容即为两者差分的描述。
运行时将Base Apk中的dex与补丁包进行合成,重启后加载全新的合成后的dex文件。

特点是:重启生效。
使用到的技术有:反射、类加载、DexDiff。
github地址:https://github.com/Tencent/tinker
四、Qzone
QQ空间基于的是dex分包方案。把BUG方法修复以后,放到一个单独的dex补丁文件,让程序运行期间加载dex补丁,执行修复后的方法。如何做到这一点?
在Android中所有我们运行期间需要的类都是由ClassLoader(类加载器)进行加载。
因此让ClassLoader加载全新的类替换掉出现Bug的类即可完成热修复。

特点是:重启生效。
使用到的技术有:反射、类加载。
网友评论