public static <T> T await(Future<T> future) throws IOException, TransformException, InterruptedException { try { return future.get(); } catch (ExecutionException e) { if (e.getCause() instanceof IOException) { throw (IOException) e.getCause(); } else if (e.getCause() instanceof RuntimeException) { throw (RuntimeException) e.getCause(); } else if (e.getCause() instanceof Error) { throw (Error) e.getCause(); } throw new TransformException(e.getCause()); } }
@Override public void transform(@NonNull final TransformInvocation transformInvocation) throws TransformException, InterruptedException, IOException { try { runJack(transformInvocation); } catch (ProcessException | ClassNotFoundException | JackToolchain.ToolchainException e) { throw new TransformException(e); } }
@Override public void transform(@NonNull final TransformInvocation transformInvocation) throws TransformException, InterruptedException, IOException { try { runJack(transformInvocation); } catch (ProcessException | ClassNotFoundException | JackToolchain.ToolchainException e) { throw new TransformException(e); } }
public <T> void loadSync(Consumer<T> consumer) throws IOException, TransformException { try { new SingleReadTask<>(consumer).call(); } catch (Exception e) { if (e instanceof IOException) { throw (IOException) e; } else if (e instanceof RuntimeException) { throw (RuntimeException) e; } else { throw new TransformException(e); } } }
@NonNull private File getZipAlignExe() throws TransformException { final TargetInfo info = androidBuilder.getTargetInfo(); if (info == null) { throw new TransformException("Cannot find zipAlign executable, no target info set"); } String path1 = info.getBuildTools().getPath(ZIP_ALIGN); if (path1 == null) { throw new TransformException("Cannot find zipAlign executable for build tools " + info.getBuildTools().getLocation()); } return new File(path1); }
private BaseVariant getVariant(Context context) throws TransformException { TransformTask transformTask = (TransformTask)context; Project project = transformTask.getProject(); List<BaseVariant> variants = new ArrayList<>(); if (project.getPlugins().hasPlugin(LibraryPlugin.class)) { LibraryExtension android = project.getExtensions().getByType(LibraryExtension.class); variants.addAll(android.getLibraryVariants()); variants.addAll(android.getTestVariants()); variants.addAll(android.getUnitTestVariants()); } else if (project.getPlugins().hasPlugin(AppPlugin.class)) { AppExtension android = project.getExtensions().getByType(AppExtension.class); variants.addAll(android.getApplicationVariants()); variants.addAll(android.getTestVariants()); variants.addAll(android.getUnitTestVariants()); } else if (project.getPlugins().hasPlugin(TestPlugin.class)) { TestExtension android = project.getExtensions().getByType(TestExtension.class); variants.addAll(android.getApplicationVariants()); } else { throw new TransformException(project.getName() + " isn't an Android project"); } Optional<BaseVariant> variant = variants.stream().filter(v -> transformTask.getVariantName().equals(v.getName())).findFirst(); if (!variant.isPresent()) { throw new TransformException("Variant not found: " + project.getName() + " / " + transformTask.getVariantName()); } return variant.get(); }
throw new TransformException( String.format("Cannot delete file %1$s", outputFile.getAbsolutePath())); throw new TransformException("Unhandled status " + status);
@NonNull protected File generateSplitApk(@NonNull DexFiles dexFiles) throws IOException, KeytoolException, PackagerException, InterruptedException, ProcessException, TransformException { String uniqueName = dexFiles.encodeName(); final File alignedOutput = new File(outputDirectory, uniqueName + ".apk"); Files.createParentDirs(alignedOutput); File resPackageFile = generateSplitApkManifest(uniqueName); // packageCodeSplitApk uses a temporary directory for incremental runs. Since we don't // do incremental builds here, make sure it gets an empty directory. File tempDir = new File(supportDirectory, "package_" + uniqueName); if (!tempDir.exists() && !tempDir.mkdirs()) { throw new TransformException("Cannot create temporary folder " + tempDir.getAbsolutePath()); } FileUtils.cleanOutputDir(tempDir); androidBuilder.packageCodeSplitApk( resPackageFile, dexFiles.dexFiles, signingConf, alignedOutput, tempDir, ApkCreatorFactories.fromProjectProperties(project, true)); instantRunBuildContext.addChangedFile(FileType.SPLIT, alignedOutput); //noinspection ResultOfMethodCallIgnored resPackageFile.delete(); return alignedOutput; }
new DexFiles(dexFiles, directoryInput.getName())); } catch (Exception e) { throw new TransformException(e); break; default: throw new TransformException(String.format( "Unhandled status %1$s for %2$s", fileEntry.getValue(), new DexFiles(ImmutableSet.copyOf(files), directoryInput.getName())); } catch (Exception e) { throw new TransformException(e); } catch (LoggedErrorException e) { logger.error("Exception while generating split APKs " + e.getMessage()); throw new TransformException(e);
throw new TransformException(e); } catch (NotFoundException e) { throw new IOException(e);
} catch (Exception e) { logger.error("Error while generating dependencies split APK", e); throw new TransformException(e);
.map(QualifiedContent::getFile) .collect(Collectors.toList()); throw new TransformException(new DuplicateFileException(key, sources));
throw new TransformException(e); } catch (IOException e) { throw new TransformException(e); } finally { jarMerger.close();
@Override public void transform(@NonNull TransformInvocation invocation) throws IOException, TransformException, InterruptedException { // Re-direct the output to appropriate log levels, just like the official ProGuard task. LoggingManager loggingManager = invocation.getContext().getLogging(); loggingManager.captureStandardOutput(LogLevel.INFO); loggingManager.captureStandardError(LogLevel.WARN); try { File input = verifyInputs(invocation.getReferencedInputs()); shrinkWithProguard(input); computeList(input); } catch (ParseException | ProcessException e) { throw new TransformException(e); } }
new File(outputFolder, "classes.dex")); } catch (ProcessException e) { throw new TransformException(e); } finally { variantScope.getInstantRunBuildContext().stopRecording(
throw e; } catch (Exception e) { throw new TransformException(e);
outputHandler); } catch (Exception e) { throw new TransformException(e);