Search in sources :

Example 1 with HotPatchInput

use of com.taobao.android.inputs.HotPatchInput in project atlas by alibaba.

the class TPatchTask method createInput.

private BaseInput createInput(ApkBO apkBO, ApkBO newApkBO, boolean retainMainBundleRes) throws IOException {
    TpatchInput tpatchInput = null;
    if (getProject().hasProperty("hotfix")) {
        tpatchInput = new HotPatchInput();
    } else {
        tpatchInput = new DexPatchInput();
    }
    tpatchInput.baseApkBo = apkBO;
    tpatchInput.newApkBo = newApkBO;
    tpatchInput.baseApkFileList = patchContext.getBaseApkFiles();
    tpatchInput.newApkFileList = patchContext.getNewApkFiles(appVariantContext);
    tpatchInput.outPatchDir = outPatchFolder;
    tpatchInput.productName = patchContext.appSignName;
    tpatchInput.outPutJson = new File(getOutPatchFolder(), "patchs.json");
    tpatchInput.artifactBundleInfos = patchContext.artifactBundleInfos;
    tpatchInput.diffBundleDex = true;
    tpatchInput.newPatch = patchContext.newPatch;
    tpatchInput.mainBundleName = patchContext.mainBundleName;
    tpatchInput.retainMainBundleRes = retainMainBundleRes;
    if (StringUtils.isNotBlank(patchContext.excludeFiles)) {
        tpatchInput.notIncludeFiles = (patchContext.excludeFiles.split(","));
    }
    if (apkBO.getVersionName().equals(newApkBO.getVersionName())) {
        if (tpatchInput instanceof HotPatchInput) {
            ((HotPatchInput) tpatchInput).hotClassListFile = patchContext.hotClassListFile;
            ((HotPatchInput) tpatchInput).patchType = PatchType.HOTFIX;
            ((HotPatchInput) tpatchInput).excludeClasses = patchContext.excludeClasses;
        } else {
            tpatchInput.patchType = PatchType.DEXPATCH;
            ((DexPatchInput) tpatchInput).patchClasses = patchContext.patchClasses;
            ((DexPatchInput) tpatchInput).excludeClasses = patchContext.excludeClasses;
        }
        tpatchInput.mainBundleName = "com.taobao.maindex";
    } else {
        tpatchInput.patchType = PatchType.TPATCH;
        tpatchInput.createHisPatch = true;
        tpatchInput.diffNativeSo = patchContext.diffNativeSo;
        tpatchInput.diffBundleSo = patchContext.diffBundleSo;
        tpatchInput.bundleWhiteList = appVariantContext.bundleListCfg;
        tpatchInput.createAll = StringUtils.isEmpty(patchContext.tpatchHistoryUrl);
        tpatchInput.LAST_PATCH_URL = patchContext.LAST_PATCH_URL;
        tpatchInput.hisPatchUrl = patchContext.tpatchHistoryUrl;
        if (null != patchContext.patchVersions) {
            tpatchInput.versionList = patchContext.patchVersions;
        }
    }
    List<Pair<BundleBO, BundleBO>> remoteBundles = new ArrayList<>();
    // Get the remote bundle
    for (AwbBundle awbBundle : AtlasBuildContext.awbBundleMap.values()) {
        if (awbBundle.isRemote) {
            File bundleFile = awbBundle.outputBundleFile;
            getProject().getLogger().error("add bundle compare " + bundleFile.getAbsolutePath());
            BundleBO newBundleBO = new BundleBO(awbBundle.getResolvedCoordinates().getArtifactId(), bundleFile, "");
            File baseBundleFile = new File(patchContext.apExplodeFolder, "remotebundles/" + bundleFile.getName());
            getProject().getLogger().error("add bundle compare base : " + baseBundleFile.getAbsolutePath());
            BundleBO baseBundleBO = null;
            if (baseBundleFile.exists()) {
                getProject().getLogger().error("add bundle compare " + baseBundleFile.getAbsolutePath() + "->" + bundleFile.getAbsolutePath());
                baseBundleBO = new BundleBO(awbBundle.getResolvedCoordinates().getArtifactId(), baseBundleFile, "");
            }
            remoteBundles.add(Pair.of(baseBundleBO, newBundleBO));
        }
    }
    if (remoteBundles.size() > 0) {
        tpatchInput.splitDiffBundle = remoteBundles;
    }
    return tpatchInput;
}
Also used : BundleBO(com.taobao.android.tpatch.model.BundleBO) DexPatchInput(com.taobao.android.inputs.DexPatchInput) ArrayList(java.util.ArrayList) HotPatchInput(com.taobao.android.inputs.HotPatchInput) AwbBundle(com.taobao.android.builder.dependency.model.AwbBundle) TpatchInput(com.taobao.android.inputs.TpatchInput) Pair(com.android.utils.Pair)

Example 2 with HotPatchInput

use of com.taobao.android.inputs.HotPatchInput 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)

Aggregations

HotPatchInput (com.taobao.android.inputs.HotPatchInput)2 ArrayList (java.util.ArrayList)2 Pair (com.android.utils.Pair)1 AwbBundle (com.taobao.android.builder.dependency.model.AwbBundle)1 BundleDiffResult (com.taobao.android.differ.dex.BundleDiffResult)1 DexPatchInput (com.taobao.android.inputs.DexPatchInput)1 TpatchInput (com.taobao.android.inputs.TpatchInput)1 DexDiffInfo (com.taobao.android.object.DexDiffInfo)1 BundleBO (com.taobao.android.tpatch.model.BundleBO)1