阿里老框架热更新:https://github.com/alibaba/AndFix
使用
0.命令行生成拆分包 :
1
| apkpatch.bat -f 修复的apk -t 老的apk -o 输出 -k 签名文件 -p 签名密码 -a 签名别名 -e 签名别名密码
|
1.PatchManager.init()初始化
2.PatchManager.addPatch(path);
3.PatchManager.loadPatch();
源码分析
1.初始化,检测当前app的patch目录是否存在,并且检测当前版本是否与本地相匹配。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| public void init(String appVersion) { if (!mPatchDir.exists() && !mPatchDir.mkdirs()) { Log.e(TAG, "patch dir create error."); return; } else if (!mPatchDir.isDirectory()) { mPatchDir.delete(); return; } SharedPreferences sp = mContext.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE); String ver = sp.getString(SP_VERSION, null); if (ver == null || !ver.equalsIgnoreCase(appVersion)) { cleanPatch(); sp.edit().putString(SP_VERSION, appVersion).commit(); } else { initPatchs(); } }
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| SortedSet<Patch> mPatchs = new ConcurrentSkipListSet<Patch>(); private Patch addPatch(File file) { Patch patch = null; if (file.getName().endsWith(SUFFIX)) { try { patch = new Patch(file); mPatchs.add(patch); } catch (IOException e) { Log.e(TAG, "addPatch", e); } } return patch; }
|
2.加载
上一篇:手动做一套自己的RockaIOC
下一篇:JNI - C基础2