use of com.android.tools.build.bundletool.preprocessors.AppBundleRecompressor in project bundletool by google.
the class BuildApksCommand method execute.
public Path execute() {
validateInput();
Path outputDirectory = getOutputFormat().equals(APK_SET) ? getOutputFile().getParent() : getOutputFile();
if (outputDirectory != null && Files.notExists(outputDirectory)) {
logger.info("Output directory '" + outputDirectory + "' does not exist, creating it.");
FileUtils.createDirectories(outputDirectory);
}
try (TempDirectory tempDir = new TempDirectory(getClass().getSimpleName())) {
Path bundlePath;
// The old APK serializer relies on the compression of entries in the App Bundle.
// Unfortunately, we don't know the compression level that was used when the bundle was built,
// so we re-compress all entries with our desired compression level.
// Exception is made when the device spec is specified, we only need a fraction of the
// entries, so re-compressing all entries would be a waste of CPU.
boolean recompressAppBundle = !getDeviceSpec().isPresent() && !getEnableApkSerializerWithoutBundleRecompression();
if (recompressAppBundle) {
bundlePath = tempDir.getPath().resolve("recompressed.aab");
new AppBundleRecompressor(getExecutorService()).recompressAppBundle(getBundlePath().toFile(), bundlePath.toFile());
} else {
bundlePath = getBundlePath();
}
try (ZipFile bundleZip = new ZipFile(bundlePath.toFile());
ZipReader zipReader = ZipReader.createFromFile(bundlePath);
Closer closer = Closer.create()) {
AppBundleValidator bundleValidator = AppBundleValidator.create(getExtraValidators());
bundleValidator.validateFile(bundleZip);
AppBundle appBundle = AppBundle.buildFromZip(bundleZip);
bundleValidator.validate(appBundle);
validateSdkBundles(closer);
AppBundlePreprocessorManager appBundlePreprocessorManager = DaggerAppBundlePreprocessorComponent.builder().setBuildApksCommand(this).build().create();
AppBundle preprocessedAppBundle = appBundlePreprocessorManager.processAppBundle(appBundle);
BuildApksManager buildApksManager = DaggerBuildApksManagerComponent.builder().setBuildApksCommand(this).setTempDirectory(tempDir).setAppBundle(preprocessedAppBundle).setZipReader(zipReader).setUseBundleCompression(recompressAppBundle).build().create();
buildApksManager.execute();
} catch (ZipException e) {
throw InvalidBundleException.builder().withCause(e).withUserMessage("The App Bundle is not a valid zip file.").build();
} finally {
if (isExecutorServiceCreatedByBundleTool()) {
getExecutorService().shutdown();
}
}
} catch (IOException e) {
throw new UncheckedIOException("An error occurred when processing the App Bundle.", e);
}
return getOutputFile();
}
Aggregations