Android热修复学习
AndFix 的学习
AndFix修复原理
修复流程:
集成:
dependencies {
compile 'com.alipay.euler:andfix:[email protected]'
}
public class AndFixManager { private AndFixManager(){} private static PatchManager mPatchManager = null; private static AndFixManager mInstance =null; public static AndFixManager getInstanc(){ if (mInstance == null){ synchronized (AndFixManager.class){ if (mInstance == null){ mInstance = new AndFixManager(); } } } return mInstance; } //初始化AndFix方法 public void initPatch(Context context){ mPatchManager = new PatchManager(context); mPatchManager.init(Utils.getVersionName(context)); mPatchManager.loadPatch(); } //加载patch文件 public void addPatch(String path){ try { if (mPatchManager != null){ mPatchManager.addPatch(path); } }catch (Exception e){ e.printStackTrace(); } } }
public class MyApplication extends Application { @Override public void onCreate() { super.onCreate(); //完成AndFix模块的初始化 initAndFix(); } private void initAndFix() { AndFixManager.getInstanc().initPatch(this); } }