热修复 tinker接入及源码分析( 十 )

  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43

  • 拷贝patch文件拷贝至私有目录,然后调用.:
    protected static boolean tryRecoverDexFiles(Tinker manager, ShareSecurityCheck checker, Context context,String patchVersionDirectory, File patchFile) {String dexMeta = checker.getMetaContentMap().get(DEX_META_FILE);boolean result = patchDexExtractViaDexDiff(context, patchVersionDirectory, dexMeta, patchFile);return result;}
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
      • 1
      • 2
      • 3
      • 4
      • 5
      • 6

      直接看xDiff
      private static boolean patchDexExtractViaDexDiff(Context context, String patchVersionDirectory, String meta, final File patchFile) {String dir = patchVersionDirectory + "/" + DEX_PATH + "/";if (!extractDexDiffInternals(context, dir, meta, patchFile, TYPE_DEX)) {TinkerLog.w(TAG, "patch recover, extractDiffInternals fail");return false;}final Tinker manager = Tinker.with(context);File dexFiles = new File(dir);File[] files = dexFiles.listFiles();...files遍历执行:DexFile.loadDexreturn true;}