- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
找到()对象中的对象根据对象找到其中的方法,传入patch相关的对应的实参,返回[]对象拿到对象中原本的方法步骤2与步骤3中的[]数组进行合并,将patch相关的dex放在数组的前面最后将合并后的数组,设置给
这里其实和Qzone的提出的方案基本是一致的 。如果你以前未了解过Qzone的方案,可以参考此文:
(2)合成patch
这里的入口为:
TinkerInstaller.onReceiveUpgradePatch(getApplicationContext(),Environment.getExternalStorageDirectory().getAbsolutePath() + "/patch_signed.apk");
- 1
- 2
- 1
- 2
上述代码会调用中的方法:
# DefaultPatchListener@Overridepublic int onPatchReceived(String path) {int returnCode = patchCheck(path);if (returnCode == ShareConstants.ERROR_PATCH_OK) {TinkerPatchService.runPatchService(context, path);} else {Tinker.with(context).getLoadReporter().onLoadPatchListenerReceiveFail(new File(path), returnCode);}return returnCode;}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
首先对的相关配置()以及patch的合法性进行检测,如果合法,则调用.(, path); 。
public static void runPatchService(Context context, String path) {try {Intent intent = new Intent(context, TinkerPatchService.class);intent.putExtra(PATCH_PATH_EXTRA, path);intent.putExtra(RESULT_CLASS_EXTRA, resultServiceClass.getName());context.startService(intent);} catch (Throwable throwable) {TinkerLog.e(TAG, "start patch service fail, exception:" + throwable);}}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
是的子类,这里通过设置了两个参数,一个是patch的路径,一个是,该值是调用.的时候设置的,默认为.class 。由于是,直接看即可,如果你对陌生,可以查看此文: 完全解析 当遇到
。
@Overrideprotected void onHandleIntent(Intent intent) {final Context context = getApplicationContext();Tinker tinker = Tinker.with(context);String path = getPatchPathExtra(intent);File patchFile = new File(path);boolean result;increasingPriority();PatchResult patchResult = new PatchResult();result = upgradePatchProcessor.tryPatch(context, path, patchResult);patchResult.isSuccess = result;patchResult.rawPatchFilePath = path;patchResult.costTime = cost;patchResult.e = e;AbstractResultService.runResultService(context, patchResult, getPatchResultExtra(intent));}