Search in sources :

Example 1 with DexDiffer

use of com.taobao.android.differ.dex.DexDiffer in project atlas by alibaba.

the class ApkPatch method doPatch.

public File doPatch() throws PatchException {
    try {
        File aptchFolder = new File(out, name);
        File smaliDir = new File(aptchFolder, "smali");
        if (!smaliDir.exists()) {
            smaliDir.mkdirs();
        }
        try {
            FileUtils.cleanDirectory(smaliDir);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        File dexFile = new File(aptchFolder, "diff.dex");
        if (dexFile.exists() && !dexFile.delete()) {
            throw new RuntimeException("diff.dex can't be removed.");
        }
        File outFile = new File(aptchFolder, "diff" + SUFFIX);
        if (outFile.exists() && !outFile.delete()) {
            throw new RuntimeException("diff" + SUFFIX + " can't be removed.");
        }
        currentTimeStamp = System.currentTimeMillis();
        DexDiffer dexDiffer = new DexDiffer(baseFiles, newFiles, 19);
        // 创建白名单过滤类
        if ((this.filterPath != null) && !(this.filterPath.equals(""))) {
            dexDiffer.createFilter(this.filterPath);
        }
        //diff
        DexDiffInfo info = dexDiffer.doDiff();
        dexDiffer.setDexDiffFilter(new AndFixFilterImpl(info));
        //diffFilter
        dexDiffer.dexFilter();
        info.update();
        //写json
        if (null != diffFile && null != diffJsonFile) {
            info.writeToFile(name, diffFile, diffJsonFile);
        }
        //生成dex
        classes = SmaliDiffUtils.buildCode(smaliDir, dexFile, info);
        if (null == classes || classes.size() <= 0) {
            return null;
        }
        //是否修改dex
        if (APatchTool.debug) {
            PatchMethodTool.modifyMethod(dexFile.getAbsolutePath(), dexFile.getAbsolutePath(), true);
        }
        File smaliDir2 = new File(aptchFolder, "smali2");
        if (!smaliDir2.exists()) {
            smaliDir2.mkdirs();
        }
        try {
            FileUtils.cleanDirectory(smaliDir2);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        prepareClasses = buildPrepareClass(smaliDir2, newFiles, info);
        DexDiffInfo.release();
        build(outFile, dexFile);
        File file = release(aptchFolder, dexFile, outFile);
        release();
        return file;
    } catch (Exception e) {
        throw new PatchException(e);
    }
}
Also used : DexDiffInfo(com.taobao.android.object.DexDiffInfo) DexDiffer(com.taobao.android.differ.dex.DexDiffer) IOException(java.io.IOException) PatchException(com.taobao.android.differ.dex.PatchException) File(java.io.File) PatchException(com.taobao.android.differ.dex.PatchException) IOException(java.io.IOException)

Aggregations

DexDiffer (com.taobao.android.differ.dex.DexDiffer)1 PatchException (com.taobao.android.differ.dex.PatchException)1 DexDiffInfo (com.taobao.android.object.DexDiffInfo)1 File (java.io.File)1 IOException (java.io.IOException)1