Search in sources :

Example 1 with EntryOption

use of com.android.tools.build.bundletool.io.ZipBuilder.EntryOption in project bundletool by google.

the class AppBundleSerializer method writeToDisk.

/**
 * Writes the App Bundle on disk at the given location.
 */
public void writeToDisk(AppBundle bundle, Path pathOnDisk) throws IOException {
    ZipBuilder zipBuilder = new ZipBuilder();
    EntryOption[] compression = allEntriesUncompressed ? new EntryOption[] { EntryOption.UNCOMPRESSED } : new EntryOption[0];
    zipBuilder.addFileWithProtoContent(ZipPath.create(BUNDLE_CONFIG_FILE_NAME), bundle.getBundleConfig(), compression);
    // APEX bundles do not have metadata files.
    if (bundle.getFeatureModules().isEmpty() || !bundle.isApex()) {
        for (Entry<ZipPath, ByteSource> metadataEntry : bundle.getBundleMetadata().getFileContentMap().entrySet()) {
            zipBuilder.addFile(METADATA_DIRECTORY.resolve(metadataEntry.getKey()), metadataEntry.getValue(), compression);
        }
    }
    for (BundleModule module : bundle.getModules().values()) {
        ZipPath moduleDir = ZipPath.create(module.getName().toString());
        for (ModuleEntry entry : module.getEntries()) {
            ZipPath entryPath = moduleDir.resolve(entry.getPath());
            zipBuilder.addFile(entryPath, entry.getContent(), compression);
        }
        // Special module files are not represented as module entries (above).
        zipBuilder.addFileWithProtoContent(moduleDir.resolve(SpecialModuleEntry.ANDROID_MANIFEST.getPath()), module.getAndroidManifest().getManifestRoot().getProto(), compression);
        module.getAssetsConfig().ifPresent(assetsConfig -> zipBuilder.addFileWithProtoContent(moduleDir.resolve(SpecialModuleEntry.ASSETS_TABLE.getPath()), assetsConfig, compression));
        module.getNativeConfig().ifPresent(nativeConfig -> zipBuilder.addFileWithProtoContent(moduleDir.resolve(SpecialModuleEntry.NATIVE_LIBS_TABLE.getPath()), nativeConfig, compression));
        module.getResourceTable().ifPresent(resourceTable -> zipBuilder.addFileWithProtoContent(moduleDir.resolve(SpecialModuleEntry.RESOURCE_TABLE.getPath()), resourceTable, compression));
        module.getApexConfig().ifPresent(apexConfig -> zipBuilder.addFileWithProtoContent(moduleDir.resolve(SpecialModuleEntry.APEX_TABLE.getPath()), apexConfig, compression));
        module.getRuntimeEnabledSdkConfig().ifPresent(runtimeEnabledSdkConfig -> zipBuilder.addFileWithProtoContent(moduleDir.resolve(SpecialModuleEntry.RUNTIME_ENABLED_SDK_CONFIG.getPath()), runtimeEnabledSdkConfig, compression));
    }
    zipBuilder.writeTo(pathOnDisk);
}
Also used : SpecialModuleEntry(com.android.tools.build.bundletool.model.BundleModule.SpecialModuleEntry) ModuleEntry(com.android.tools.build.bundletool.model.ModuleEntry) ByteSource(com.google.common.io.ByteSource) EntryOption(com.android.tools.build.bundletool.io.ZipBuilder.EntryOption) ZipPath(com.android.tools.build.bundletool.model.ZipPath) BundleModule(com.android.tools.build.bundletool.model.BundleModule)

Aggregations

EntryOption (com.android.tools.build.bundletool.io.ZipBuilder.EntryOption)1 BundleModule (com.android.tools.build.bundletool.model.BundleModule)1 SpecialModuleEntry (com.android.tools.build.bundletool.model.BundleModule.SpecialModuleEntry)1 ModuleEntry (com.android.tools.build.bundletool.model.ModuleEntry)1 ZipPath (com.android.tools.build.bundletool.model.ZipPath)1 ByteSource (com.google.common.io.ByteSource)1