use of com.taobao.android.outputs.DexPatchFile in project atlas by alibaba.
the class DexPatchTool method doPatch.
@Override
public PatchFile doPatch() throws Exception {
TpatchInput tpatchInput = (TpatchInput) input;
DexPatchFile tpatchFile = new DexPatchFile();
tpatchFile.diffJson = new File(tpatchInput.outPatchDir, "diff.json");
tpatchFile.patchInfo = new File(tpatchInput.outPatchDir, "patchInfo.json");
final File patchTmpDir = new File(tpatchInput.outPatchDir, "dexpatch-tmp");
final File mainDiffFolder = new File(patchTmpDir, tpatchInput.mainBundleName);
patchTmpDir.mkdirs();
FileUtils.cleanDirectory(patchTmpDir);
mainDiffFolder.mkdirs();
Profiler.release();
Profiler.enter("unzip apks");
// unzip apk
File unzipFolder = unzipApk(((TpatchInput) input).outPatchDir);
final File newApkUnzipFolder = new File(unzipFolder, NEW_APK_UNZIP_NAME);
final File baseApkUnzipFolder = new File(unzipFolder, BASE_APK_UNZIP_NAME);
Profiler.release();
ExecutorServicesHelper executorServicesHelper = new ExecutorServicesHelper();
String taskName = "diffBundleTask";
//
Collection<File> soFiles = FileUtils.listFiles(newApkUnzipFolder, new String[] { "so" }, true);
// process remote bumdle
if (tpatchInput.splitDiffBundle != null) {
for (final Pair<BundleBO, BundleBO> bundle : ((TpatchInput) input).splitDiffBundle) {
executorServicesHelper.submitTask(taskName, new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
processBundleFiles(bundle.getSecond().getBundleFile(), bundle.getFirst().getBundleFile(), patchTmpDir);
return true;
}
});
}
}
Profiler.enter("awbspatch");
executorServicesHelper.submitTask(taskName, new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
// 得到主bundle的dex diff文件
createBundleDexPatch(newApkUnzipFolder, baseApkUnzipFolder, mainDiffFolder, true);
return true;
}
});
for (final File soFile : soFiles) {
System.out.println("do dexpatch:" + soFile.getAbsolutePath());
final String relativePath = PathUtils.toRelative(newApkUnzipFolder, soFile.getAbsolutePath());
if (null != tpatchInput.notIncludeFiles && pathMatcher.match(tpatchInput.notIncludeFiles, relativePath)) {
continue;
}
executorServicesHelper.submitTask(taskName, new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
File destFile = new File(patchTmpDir, tpatchInput.mainBundleName + "/" + relativePath);
File baseSoFile = new File(baseApkUnzipFolder, relativePath);
if (isBundleFile(soFile)) {
processBundleFiles(soFile, baseSoFile, patchTmpDir);
}
return true;
}
});
}
executorServicesHelper.waitTaskCompleted(taskName);
executorServicesHelper.stop();
Profiler.release();
Profiler.enter("ziptpatchfile");
// zip file
File patchFile = createDexPatchFile(tpatchInput.outPatchDir, patchTmpDir);
tpatchFile.patchFile = patchFile;
if (!patchFile.exists()) {
return null;
}
PatchInfo curPatchInfo = createBasePatchInfo(patchFile);
Profiler.release();
Profiler.enter("writejson");
BuildPatchInfos buildPatchInfos = new BuildPatchInfos();
buildPatchInfos.getPatches().add(curPatchInfo);
buildPatchInfos.setBaseVersion(input.baseApkBo.getVersionName());
buildPatchInfos.setDiffBundleDex(true);
FileUtils.writeStringToFile(tpatchInput.outPutJson, JSON.toJSONString(buildPatchInfos));
// 删除临时的目录
FileUtils.deleteDirectory(patchTmpDir);
apkDiff.setBaseApkVersion(input.baseApkBo.getVersionName());
apkDiff.setNewApkVersion(input.newApkBo.getVersionName());
apkDiff.setBundleDiffResults(bundleDiffResults);
boolean newApkFileExist = input.newApkBo.getApkFile().exists() && input.newApkBo.getApkFile().isFile();
if (newApkFileExist) {
apkDiff.setNewApkMd5(MD5Util.getFileMD5String(input.newApkBo.getApkFile()));
}
apkDiff.setFileName(input.newApkBo.getApkName());
apkPatchInfos.setBaseApkVersion(input.baseApkBo.getVersionName());
apkPatchInfos.setNewApkVersion(input.newApkBo.getVersionName());
apkPatchInfos.setBundleDiffResults(diffPatchInfos);
apkPatchInfos.setFileName(patchFile.getName());
apkPatchInfos.setNewApkMd5(MD5Util.getFileMD5String(patchFile));
FileUtils.writeStringToFile(tpatchFile.diffJson, JSON.toJSONString(apkDiff));
FileUtils.writeStringToFile(tpatchFile.patchInfo, JSON.toJSONString(apkPatchInfos));
FileUtils.copyFileToDirectory(tpatchFile.diffJson, tpatchInput.outPatchDir.getParentFile(), true);
if (newApkFileExist) {
FileUtils.copyFileToDirectory(input.newApkBo.getApkFile(), tpatchInput.outPatchDir.getParentFile(), true);
}
Profiler.release();
logger.warning(Profiler.dump());
return tpatchFile;
}
Aggregations