use of com.android.bundle.Files.NativeLibraries in project bundletool by google.
the class BuildBundleCommand method execute.
public void execute() {
validateInput();
try (Closer closer = Closer.create()) {
ImmutableList.Builder<ZipFile> moduleZipFilesBuilder = ImmutableList.builder();
for (Path modulePath : getModulesPaths()) {
try {
moduleZipFilesBuilder.add(closer.register(new ZipFile(modulePath.toFile())));
} catch (ZipException e) {
throw CommandExecutionException.builder().withCause(e).withInternalMessage("File '%s' does not seem to be a valid ZIP file.", modulePath).build();
} catch (IOException e) {
throw CommandExecutionException.builder().withCause(e).withInternalMessage("Unable to read file '%s'.", modulePath).build();
}
}
ImmutableList<ZipFile> moduleZipFiles = moduleZipFilesBuilder.build();
// Read the Bundle Config file if provided by the developer.
BundleConfig bundleConfig = getBundleConfig().orElse(BundleConfig.getDefaultInstance()).toBuilder().setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).build();
ImmutableList<BundleModule> modules = new BundleModulesValidator().validate(moduleZipFiles, bundleConfig);
checkState(moduleZipFiles.size() == modules.size(), "Incorrect number of modules parsed (%s != %s).", moduleZipFiles.size(), modules.size());
ImmutableList.Builder<BundleModule> modulesWithTargeting = ImmutableList.builder();
for (BundleModule module : modules) {
BundleModule.Builder moduleWithTargeting = module.toBuilder();
Optional<Assets> assetsTargeting = generateAssetsTargeting(module);
assetsTargeting.ifPresent(moduleWithTargeting::setAssetsConfig);
Optional<NativeLibraries> nativeLibrariesTargeting = generateNativeLibrariesTargeting(module);
nativeLibrariesTargeting.ifPresent(moduleWithTargeting::setNativeConfig);
Optional<ApexImages> apexImagesTargeting = generateApexImagesTargeting(module);
apexImagesTargeting.ifPresent(moduleWithTargeting::setApexConfig);
modulesWithTargeting.add(moduleWithTargeting.build());
}
AppBundle appBundle = AppBundle.buildFromModules(modulesWithTargeting.build(), bundleConfig, getBundleMetadata());
Path outputDirectory = getOutputPath().toAbsolutePath().getParent();
if (Files.notExists(outputDirectory)) {
logger.info("Output directory '" + outputDirectory + "' does not exist, creating it.");
FileUtils.createDirectories(outputDirectory);
}
if (getOverwriteOutput()) {
Files.deleteIfExists(getOutputPath());
}
new AppBundleSerializer(getUncompressedBundle()).writeToDisk(appBundle, getOutputPath());
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
Aggregations