Search in sources :

Example 6 with ProcessException

use of com.android.ide.common.process.ProcessException in project atlas by alibaba.

the class AtlasDexArchiveBuilderTransform method convertToDexArchive.

private List<File> convertToDexArchive(@NonNull Context context, @NonNull QualifiedContent input, @NonNull TransformOutputProvider outputProvider, boolean isIncremental) throws Exception {
    logger.verbose("Dexing {}", input.getFile().getAbsolutePath());
    ImmutableList.Builder<File> dexArchives = ImmutableList.builder();
    for (int bucketId = 0; bucketId < NUMBER_OF_BUCKETS; bucketId++) {
        File preDexOutputFile = getPreDexFile(outputProvider, input, bucketId);
        if (input.getFile().isDirectory()) {
            File cachedVersion = cacheHandler.getCachedVersionIfPresent(input.getFile());
            dexArchives.add(preDexOutputFile);
            if (cachedVersion != null) {
                FileUtils.copyDirectoryContentToDirectory(cachedVersion, preDexOutputFile);
                return dexArchives.build();
            }
        }
        if (preDexOutputFile.isDirectory() && preDexOutputFile.exists()) {
            FileUtils.cleanOutputDir(preDexOutputFile);
        } else {
            FileUtils.deleteIfExists(preDexOutputFile);
        }
        AtlasDexArchiveBuilderTransform.DexConversionParameters parameters = new AtlasDexArchiveBuilderTransform.DexConversionParameters(input, preDexOutputFile, NUMBER_OF_BUCKETS, bucketId, minSdkVersion, dexOptions.getAdditionalParameters(), inBufferSize, outBufferSize, dexer, isDebuggable, isIncremental, false);
        if (useGradleWorkers) {
            context.getWorkerExecutor().submit(DexArchiveBuilderTransform.DexConversionWorkAction.class, configuration -> {
                configuration.setIsolationMode(IsolationMode.NONE);
                configuration.setParams(parameters);
            });
        } else {
            executor.execute(() -> {
                ProcessOutputHandler outputHandler = new ParsingProcessOutputHandler(new ToolOutputParser(new DexParser(), Message.Kind.ERROR, logger), new ToolOutputParser(new DexParser(), logger), errorReporter);
                ProcessOutput output = null;
                try (Closeable ignored = output = outputHandler.createOutput()) {
                    launchProcessing(parameters, output.getStandardOutput(), output.getErrorOutput());
                } finally {
                    if (output != null) {
                        try {
                            outputHandler.handleOutput(output);
                        } catch (ProcessException e) {
                        // ignore this one
                        }
                    }
                }
                return null;
            });
        }
    }
    List<File> files = dexArchives.build();
    return files;
}
Also used : ParsingProcessOutputHandler(com.android.ide.common.blame.ParsingProcessOutputHandler) ProcessOutputHandler(com.android.ide.common.process.ProcessOutputHandler) DexArchiveBuilderTransform(com.android.build.gradle.internal.transforms.DexArchiveBuilderTransform) ProcessException(com.android.ide.common.process.ProcessException) ToolOutputParser(com.android.ide.common.blame.parser.ToolOutputParser) DexParser(com.android.ide.common.blame.parser.DexParser) ProcessOutput(com.android.ide.common.process.ProcessOutput) JarFile(java.util.jar.JarFile) ParsingProcessOutputHandler(com.android.ide.common.blame.ParsingProcessOutputHandler)

Example 7 with ProcessException

use of com.android.ide.common.process.ProcessException in project atlas by alibaba.

the class AwbDexsMerger method merge.

public void merge(AwbBundle awbBundle) {
    File file = variantOutputContext.getVariantContext().getAwbDexAchiveOutput(awbBundle);
    List<File> awbDexFiles = new ArrayList<>();
    if (!file.exists() || !file.isDirectory()) {
        return;
    }
    awbDexFiles.addAll(org.apache.commons.io.FileUtils.listFiles(file, new String[] { "jar", "dex" }, true));
    File[] mergeDexs = file.listFiles(pathname -> pathname.getName().endsWith(".jar") || pathname.isDirectory());
    sort(awbDexFiles);
    File outPutFolder = variantOutputContext.getAwbDexOutput(awbBundle.getName());
    try {
        FileUtils.cleanOutputDir(outPutFolder);
    } catch (IOException e) {
        e.printStackTrace();
    }
    FileCache.Inputs buildCacheInputs = getBuildCacheInputs(awbDexFiles, dexingType, dexMerger, null, minSdkVersion, isDebuggable, awbBundle.getName(), ID);
    ProcessOutput output = outputHandler.createOutput();
    FileCache fileCache = BuildCacheUtils.createBuildCacheIfEnabled(variantOutputContext.getVariantContext().getProject(), variantOutputContext.getScope().getGlobalScope().getProjectOptions());
    if (fileCache == null) {
        try {
            fileCache = FileCache.getInstanceWithMultiProcessLocking(new File(AndroidLocation.getFolder(), "atlas-buildCache"));
        } catch (AndroidLocation.AndroidLocationException e) {
            e.printStackTrace();
        }
    }
    if (variantOutputContext.getVariantContext().getAtlasExtension().getTBuildConfig().getMergeBundlesDex() && !awbBundle.isRemote && awbBundle.isMBundle) {
        allDexsArchives.addAll(Arrays.asList(mergeDexs));
        return;
    }
    try {
        FileCache.QueryResult result = fileCache.createFileInCacheIfAbsent(buildCacheInputs, in -> {
            List<ForkJoinTask<Void>> mergeTasks = new ArrayList<ForkJoinTask<Void>>();
            mergeTasks.addAll(handleLegacyAndMonoDex(Arrays.asList(mergeDexs), output, outPutFolder, null));
            mergeTasks.forEach(voidForkJoinTask -> voidForkJoinTask.join());
            cacheHandler.handleMissActionResult(outPutFolder, in);
            if (output != null) {
                try {
                    outputHandler.handleOutput(output);
                } catch (ProcessException e) {
                // ignore this one
                }
            }
        });
        cacheHandler.handleQueryResult(result, outPutFolder, awbBundle.getName());
        if (awbBundle.isMBundle) {
            org.apache.commons.io.FileUtils.moveFile(new File(outPutFolder, CLASSES_DEX), new File(mainDexOut, "classes" + atomicInteger.incrementAndGet() + ".dex"));
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : ArrayList(java.util.ArrayList) ForkJoinTask(java.util.concurrent.ForkJoinTask) IOException(java.io.IOException) IOException(java.io.IOException) ProcessException(com.android.ide.common.process.ProcessException) FileCache(com.android.builder.utils.FileCache) ProcessException(com.android.ide.common.process.ProcessException) ProcessOutput(com.android.ide.common.process.ProcessOutput) File(java.io.File) AndroidLocation(com.android.prefs.AndroidLocation)

Aggregations

ProcessException (com.android.ide.common.process.ProcessException)7 ProcessOutput (com.android.ide.common.process.ProcessOutput)4 ProcessOutputHandler (com.android.ide.common.process.ProcessOutputHandler)3 File (java.io.File)3 JarFile (java.util.jar.JarFile)3 DexArchiveBuilderTransform (com.android.build.gradle.internal.transforms.DexArchiveBuilderTransform)2 AtlasBuilder (com.android.builder.core.AtlasBuilder)2 FileCache (com.android.builder.utils.FileCache)2 ParsingProcessOutputHandler (com.android.ide.common.blame.ParsingProcessOutputHandler)2 DexParser (com.android.ide.common.blame.parser.DexParser)2 ToolOutputParser (com.android.ide.common.blame.parser.ToolOutputParser)2 AndroidLocation (com.android.prefs.AndroidLocation)2 IOException (java.io.IOException)2 ForkJoinTask (java.util.concurrent.ForkJoinTask)2 NonNull (com.android.annotations.NonNull)1 Nullable (com.android.annotations.Nullable)1 AaptGeneration (com.android.build.gradle.internal.aapt.AaptGeneration)1 InstantRunBuildContext (com.android.build.gradle.internal.incremental.InstantRunBuildContext)1 SplitList (com.android.build.gradle.internal.scope.SplitList)1 AaptPackageProcessBuilder (com.android.builder.core.AaptPackageProcessBuilder)1