use of com.taobao.android.builder.tasks.transform.dex.AtlasMainDexMerger in project atlas by alibaba.
the class AtlasD8Creator method create.
public void create(AwbBundle awbBundle) {
inputFiles.stream().parallel().forEach(file -> {
if (file.exists() && file.isDirectory()) {
logger.warning("d8 to dex:" + file.getAbsolutePath());
try (ClassFileInput input = ClassFileInputs.fromPath(file.toPath())) {
dexArchiveBuilder.convert(input.entries(ClassFileInput.CLASS_MATCHER), dexOut.toPath(), false);
} catch (DexArchiveBuilderException ex) {
throw new DexArchiveBuilderException("Failed to process " + file.toPath().toString(), ex);
} catch (IOException e) {
e.printStackTrace();
}
} else {
logger.warning("d8 to dex:" + file.getAbsolutePath());
File out = new File(dexOut, FilenameUtils.getBaseName(file.getName()) + ".dex");
try {
File cacheDex = cacheHander.getCachedVersionIfPresent(file);
if (cacheDex == null || !cacheDex.exists()) {
try (ClassFileInput input = ClassFileInputs.fromPath(file.toPath())) {
dexArchiveBuilder.convert(input.entries(ClassFileInput.CLASS_MATCHER), out.toPath(), false);
} catch (DexArchiveBuilderException ex) {
throw new DexArchiveBuilderException("Failed to process " + file.toPath().toString(), ex);
}
if (out.exists()) {
cacheHander.populateCache(file, out);
}
} else {
logger.warning("hit d8 cache:" + file.getAbsolutePath());
Files.copy(cacheDex.toPath(), out.toPath(), StandardCopyOption.REPLACE_EXISTING);
}
} catch (IOException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
});
ErrorReporter errorReporter = variantContext.getScope().getGlobalScope().getAndroidBuilder().getErrorReporter();
if (!awbBundle.isMainBundle()) {
AwbDexsMerger awbDexsMerger = new AwbDexsMerger(DexingType.MONO_DEX, null, errorReporter, DexMergerTool.D8, miniSdk, isDebuggable, appVariantOutputContext);
awbDexsMerger.merge(awbBundle);
} else {
AtlasMainDexMerger atlasMainDexMerger = new AtlasMainDexMerger(multidex ? DexingType.LEGACY_MULTIDEX : DexingType.MONO_DEX, variantContext.getProject().files(mainDexList), errorReporter, DexMergerTool.D8, miniSdk, isDebuggable, appVariantOutputContext);
List<File> dexFiles = new ArrayList();
File[][] mergeDexs = { new File[0] };
dexFiles.addAll(FileUtils.listFiles(dexOut, new String[] { "dex" }, true));
mergeDexs[0] = dexOut.listFiles(new FileFilter() {
@Override
public boolean accept(File pathname) {
return pathname.isDirectory() || pathname.getName().endsWith(".dex");
}
});
atlasMainDexMerger.merge(dexFiles, mainDexOut, mergeDexs);
}
}
Aggregations