Search in sources :

Example 1 with BundleDiffResult

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

the class DexPatchTool method createBundleDexPatch.

@Override
public List<File> createBundleDexPatch(File newApkUnzipFolder, File baseApkUnzipFolder, File mainDiffFolder, boolean mainDex) throws Exception {
    List<File> dexs = Lists.newArrayList();
    // 比较主bundle的dex
    String bundleName = null;
    if (mainDex) {
        bundleName = "com.taobao.maindex";
    } else {
        bundleName = baseApkUnzipFolder.getName().substring(3).replace("_", ".");
    }
    List<File> baseDexFiles = getFolderDexFiles(baseApkUnzipFolder);
    List<File> newDexFiles = getFolderDexFiles(newApkUnzipFolder);
    File dexDiffFile = new File(mainDiffFolder, TPatchTool.DEX_NAME);
    PatchDexTool dexTool = new DexPatchDexTool(baseDexFiles, newDexFiles, DEFAULT_API_LEVEL, null, mainDex);
    dexTool.setNewPatch(((DexPatchInput) input).newPatch);
    dexTool.setExculdeClasses(((DexPatchInput) input).excludeClasses);
    dexTool.setPatchClasses(((DexPatchInput) input).patchClasses);
    DexDiffInfo dexDiffInfo = dexTool.createPatchDex(mainDiffFolder);
    if (dexDiffFile.exists()) {
        dexs.add(dexDiffFile);
        BundleDiffResult bundleDiffResult = new BundleDiffResult();
        bundleDiffResult.setBundleName(bundleName);
        bundleDiffResults.add(bundleDiffResult);
        diffPatchInfos.add(bundleDiffResult);
        dexDiffInfo.save(bundleDiffResult);
    }
    if (dexs.size() > 0) {
        bundleTypes.put(bundleName, 1);
    }
    return dexs;
}
Also used : DexDiffInfo(com.taobao.android.object.DexDiffInfo) BundleDiffResult(com.taobao.android.differ.dex.BundleDiffResult) File(java.io.File) DexPatchFile(com.taobao.android.outputs.DexPatchFile) PatchFile(com.taobao.android.outputs.PatchFile)

Example 2 with BundleDiffResult

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

the class HotPatchTool method createBundleDexPatch.

@Override
public List<File> createBundleDexPatch(File newApkUnzipFolder, File baseApkUnzipFolder, File destDexFolder, boolean mainDex) throws Exception {
    if (input instanceof HotPatchInput) {
        readClassFile(((HotPatchInput) input).hotClassListFile);
    }
    boolean hasDexPatch = false;
    boolean hasHotDexPatch = false;
    List<File> dexs = new ArrayList<>();
    String bundleName = null;
    if (mainDex) {
        bundleName = "com.taobao.maindex";
    } else {
        bundleName = baseApkUnzipFolder.getName().substring(3).replace("_", ".");
    }
    List<File> baseDexFiles = getFolderDexFiles(baseApkUnzipFolder);
    List<File> newDexFiles = getFolderDexFiles(newApkUnzipFolder);
    File hotdestDexFile = null;
    if (mainDex) {
        hotdestDexFile = new File(destDexFolder, "hot.dex");
    } else {
        hotdestDexFile = new File(destDexFolder, "hot.dex");
    }
    PatchDexTool dexTool = new HotDexPatchDexTool(baseDexFiles, newDexFiles, DEFAULT_API_LEVEL, null, mainDex);
    dexTool.setNewPatch(((HotPatchInput) input).newPatch);
    dexTool.setExculdeClasses(((HotPatchInput) input).excludeClasses);
    dexTool.setPatchClassList(hotClassList);
    DexDiffInfo dexDiffInfo = dexTool.createPatchDex(destDexFolder);
    if (destDexFolder.exists() && destDexFolder.listFiles() != null) {
        File dexDiffFile = new File(destDexFolder, TPatchTool.DEX_NAME);
        hasDexPatch = true;
        BundleDiffResult bundleDiffResult = new BundleDiffResult();
        bundleDiffResult.setBundleName(bundleName);
        bundleDiffResults.add(bundleDiffResult);
        diffPatchInfos.add(bundleDiffResult);
        dexDiffInfo.save(bundleDiffResult);
        dexs.add(dexDiffFile);
    }
    if (hotdestDexFile.exists()) {
        dexs.add(hotdestDexFile);
        hasHotDexPatch = true;
    }
    if (hasDexPatch && !hasHotDexPatch) {
        bundleTypes.put(bundleName, 1);
    } else if (hasDexPatch && hasHotDexPatch) {
        bundleTypes.put(bundleName, 3);
    } else if (!hasDexPatch && hasHotDexPatch) {
        bundleTypes.put(bundleName, 2);
    }
    return dexs;
}
Also used : DexDiffInfo(com.taobao.android.object.DexDiffInfo) BundleDiffResult(com.taobao.android.differ.dex.BundleDiffResult) ArrayList(java.util.ArrayList) HotPatchInput(com.taobao.android.inputs.HotPatchInput)

Example 3 with BundleDiffResult

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

the class TPatchTool method createBundleDexPatch.

/**
 * get bundle diff dex file
 *
 * @param newApkUnzipFolder
 * @param baseApkUnzipFolder
 * @param destDex
 * @param tmpDexFile
 * @param diffTxtFile
 * @return
 * @throws IOException
 * @throws RecognitionException
 */
public List<File> createBundleDexPatch(File newApkUnzipFolder, File baseApkUnzipFolder, File diffDexFolder, boolean mainDex) throws Exception {
    List<File> dexs = Lists.newArrayList();
    // 比较主bundle的dex
    // if (!tmpDexFile.exists()) {
    // tmpDexFile.mkdirs();
    // }
    List<File> baseDexFiles = getFolderDexFiles(baseApkUnzipFolder);
    List<File> newDexFiles = getFolderDexFiles(newApkUnzipFolder);
    PatchDexTool dexTool = new TpatchDexTool(baseDexFiles, newDexFiles, DEFAULT_API_LEVEL, bundleClassMap.get(diffDexFolder.getName()), mainDex);
    dexTool.setNewPatch(((TpatchInput) input).newPatch);
    DexDiffInfo dexDiffInfo = dexTool.createPatchDex(diffDexFolder);
    if (diffDexFolder.listFiles() != null && diffDexFolder.listFiles().length > 0) {
        dexs.addAll(FileUtils.listFiles(diffDexFolder, new String[] { "dex" }, true));
        BundleDiffResult bundleDiffResult = new BundleDiffResult();
        if (mainDex) {
            bundleDiffResult.setBundleName("com.taobao.maindex");
        } else {
            bundleDiffResult.setBundleName(baseApkUnzipFolder.getName().substring(3).replace("_", "."));
        }
        bundleDiffResults.add(bundleDiffResult);
        diffPatchInfos.add(bundleDiffResult);
        dexDiffInfo.save(bundleDiffResult);
    }
    return dexs;
}
Also used : BundleDiffResult(com.taobao.android.differ.dex.BundleDiffResult) TpatchFile(com.taobao.android.outputs.TpatchFile) ZipFile(java.util.zip.ZipFile) PatchFile(com.taobao.android.outputs.PatchFile)

Aggregations

BundleDiffResult (com.taobao.android.differ.dex.BundleDiffResult)3 DexDiffInfo (com.taobao.android.object.DexDiffInfo)2 PatchFile (com.taobao.android.outputs.PatchFile)2 HotPatchInput (com.taobao.android.inputs.HotPatchInput)1 DexPatchFile (com.taobao.android.outputs.DexPatchFile)1 TpatchFile (com.taobao.android.outputs.TpatchFile)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 ZipFile (java.util.zip.ZipFile)1