Search in sources :

Example 1 with AwbDexsMerger

use of com.taobao.android.builder.tasks.transform.dex.AwbDexsMerger 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);
    }
}
Also used : AwbDexsMerger(com.taobao.android.builder.tasks.transform.dex.AwbDexsMerger) ArrayList(java.util.ArrayList) IOException(java.io.IOException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) ErrorReporter(com.android.builder.core.ErrorReporter) AtlasMainDexMerger(com.taobao.android.builder.tasks.transform.dex.AtlasMainDexMerger) ExecutionException(java.util.concurrent.ExecutionException) FileFilter(java.io.FileFilter) File(java.io.File)

Aggregations

ErrorReporter (com.android.builder.core.ErrorReporter)1 AtlasMainDexMerger (com.taobao.android.builder.tasks.transform.dex.AtlasMainDexMerger)1 AwbDexsMerger (com.taobao.android.builder.tasks.transform.dex.AwbDexsMerger)1 File (java.io.File)1 FileFilter (java.io.FileFilter)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 ExecutionException (java.util.concurrent.ExecutionException)1