Search in sources :

Example 91 with ZipPath

use of com.android.tools.build.bundletool.model.ZipPath in project bundletool by google.

the class ZipFlingerAppBundleSerializer method addNewEntries.

/**
 * Adds new and modified entries to an archive, compressing them.
 */
private static void addNewEntries(ZipArchive archive, ImmutableListMultimap<BundleModule, ModuleEntry> entries) throws IOException {
    for (Map.Entry<BundleModule, ModuleEntry> moduleAndEntry : entries.entries()) {
        BundleModule module = moduleAndEntry.getKey();
        ModuleEntry moduleEntry = moduleAndEntry.getValue();
        checkState(!moduleEntry.getBundleLocation().isPresent());
        ZipPath moduleDir = ZipPath.create(module.getName().toString());
        ZipPath destPath = moduleDir.resolve(moduleEntry.getPath());
        archive.add(new BytesSource(moduleEntry.getContent().read(), destPath.toString(), DEFAULT_COMPRESSION_LEVEL));
    }
}
Also used : BytesSource(com.android.zipflinger.BytesSource) SpecialModuleEntry(com.android.tools.build.bundletool.model.BundleModule.SpecialModuleEntry) ModuleEntry(com.android.tools.build.bundletool.model.ModuleEntry) ZipPath(com.android.tools.build.bundletool.model.ZipPath) HashMap(java.util.HashMap) Map(java.util.Map) BundleModule(com.android.tools.build.bundletool.model.BundleModule)

Example 92 with ZipPath

use of com.android.tools.build.bundletool.model.ZipPath in project bundletool by google.

the class BundleModuleMerger method getAllEntriesExceptDexAndSpecial.

private static ImmutableSet<ModuleEntry> getAllEntriesExceptDexAndSpecial(Set<BundleModule> bundleModulesToFuse) {
    Map<ZipPath, ModuleEntry> mergedEntriesByPath = new HashMap<>();
    bundleModulesToFuse.stream().flatMap(module -> module.getEntries().stream()).filter(moduleEntry -> !moduleEntry.getPath().startsWith(DEX_DIRECTORY) && !moduleEntry.isSpecialEntry()).forEach(moduleEntry -> {
        ModuleEntry existingModuleEntry = mergedEntriesByPath.putIfAbsent(moduleEntry.getPath(), moduleEntry);
        if (existingModuleEntry != null && !existingModuleEntry.equals(moduleEntry)) {
            throw InvalidBundleException.builder().withUserMessage("Existing module entry '%s' with different contents.", moduleEntry.getPath()).build();
        }
    });
    return ImmutableSet.copyOf(mergedEntriesByPath.values());
}
Also used : ImmutableListMultimap.flatteningToImmutableListMultimap(com.google.common.collect.ImmutableListMultimap.flatteningToImmutableListMultimap) FUSE_APPLICATION_ELEMENTS_FROM_FEATURE_MANIFESTS(com.android.tools.build.bundletool.model.version.VersionGuardedFeature.FUSE_APPLICATION_ELEMENTS_FROM_FEATURE_MANIFESTS) BundleModuleName(com.android.tools.build.bundletool.model.BundleModuleName) ZipPath(com.android.tools.build.bundletool.model.ZipPath) AndroidManifest(com.android.tools.build.bundletool.model.AndroidManifest) HashMap(java.util.HashMap) AndroidManifestMerger.fusingMergerOnlyReplaceActivities(com.android.tools.build.bundletool.mergers.AndroidManifestMerger.fusingMergerOnlyReplaceActivities) AndroidManifestMerger.fusingMergerApplicationElements(com.android.tools.build.bundletool.mergers.AndroidManifestMerger.fusingMergerApplicationElements) HashMultimap(com.google.common.collect.HashMultimap) Multimaps.toMultimap(com.google.common.collect.Multimaps.toMultimap) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) ModuleType(com.android.tools.build.bundletool.model.BundleModule.ModuleType) Version(com.android.tools.build.bundletool.model.version.Version) ResourceTable(com.android.aapt.Resources.ResourceTable) DEX_DIRECTORY(com.android.tools.build.bundletool.model.BundleModule.DEX_DIRECTORY) BundleToolVersion(com.android.tools.build.bundletool.model.version.BundleToolVersion) ImmutableSet(com.google.common.collect.ImmutableSet) InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Set(java.util.Set) IOException(java.io.IOException) NativeLibraries(com.android.bundle.Files.NativeLibraries) ApexImages(com.android.bundle.Files.ApexImages) MERGE_INSTALL_TIME_MODULES_INTO_BASE(com.android.tools.build.bundletool.model.version.VersionGuardedFeature.MERGE_INSTALL_TIME_MODULES_INTO_BASE) Stream(java.util.stream.Stream) BundleConfig(com.android.bundle.Config.BundleConfig) ModuleEntry(com.android.tools.build.bundletool.model.ModuleEntry) ImmutableListMultimap(com.google.common.collect.ImmutableListMultimap) Optional(java.util.Optional) Assets(com.android.bundle.Files.Assets) AppBundle(com.android.tools.build.bundletool.model.AppBundle) BundleModule(com.android.tools.build.bundletool.model.BundleModule) HashMap(java.util.HashMap) ModuleEntry(com.android.tools.build.bundletool.model.ModuleEntry) ZipPath(com.android.tools.build.bundletool.model.ZipPath)

Example 93 with ZipPath

use of com.android.tools.build.bundletool.model.ZipPath in project bundletool by google.

the class ApkPathManager method getApkPath.

/**
 * Returns a unique file path for the given ModuleSplit.
 *
 * <p>Note that calling this method twice for the same object will return a different result since
 * each returned value is unique.
 */
public ZipPath getApkPath(ModuleSplit moduleSplit) {
    if (apkBuildMode.equals(ApkBuildMode.UNIVERSAL)) {
        return ZipPath.create("universal.apk");
    }
    String moduleName = moduleSplit.getModuleName().getName();
    String targetingSuffix = getTargetingSuffix(moduleSplit);
    ZipPath directory;
    String apkFileName;
    switch(moduleSplit.getSplitType()) {
        case SPLIT:
            directory = ZipPath.create("splits");
            apkFileName = buildName(moduleName, targetingSuffix);
            break;
        case INSTANT:
            directory = ZipPath.create("instant");
            apkFileName = buildName("instant", moduleName, targetingSuffix);
            break;
        case STANDALONE:
            directory = ZipPath.create("standalones");
            apkFileName = buildName("standalone", targetingSuffix);
            break;
        case SYSTEM:
            if (moduleSplit.isBaseModuleSplit() && moduleSplit.isMasterSplit()) {
                directory = ZipPath.create("system");
                apkFileName = buildName("system");
            } else {
                directory = ZipPath.create("splits");
                apkFileName = buildName(moduleName, targetingSuffix);
            }
            break;
        case ASSET_SLICE:
            directory = ZipPath.create("asset-slices");
            apkFileName = buildName(moduleName, targetingSuffix);
            break;
        case ARCHIVE:
            directory = ZipPath.create("archive");
            apkFileName = buildName("archive");
            break;
        default:
            throw new IllegalStateException("Unrecognized split type: " + moduleSplit.getSplitType());
    }
    return findAndClaimUnusedPath(directory, apkFileName, fileExtension(moduleSplit));
}
Also used : ZipPath(com.android.tools.build.bundletool.model.ZipPath)

Example 94 with ZipPath

use of com.android.tools.build.bundletool.model.ZipPath in project bundletool by google.

the class BundleFilesValidatorTest method validateLibFile_directoryStructureTooShallow_throws.

@Test
public void validateLibFile_directoryStructureTooShallow_throws() throws Exception {
    ZipPath libFileDirectlyInLib = ZipPath.create("lib/libX.so");
    InvalidBundleException e = assertThrows(InvalidBundleException.class, () -> new BundleFilesValidator().validateModuleFile(libFileDirectlyInLib));
    assertThat(e).hasMessageThat().contains("paths in form 'lib/<single-directory>/<file>.so'");
}
Also used : InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) ZipPath(com.android.tools.build.bundletool.model.ZipPath) Test(org.junit.Test)

Example 95 with ZipPath

use of com.android.tools.build.bundletool.model.ZipPath in project bundletool by google.

the class BundleFilesValidatorTest method validateManifestDirectory_otherFile_throws.

@Test
public void validateManifestDirectory_otherFile_throws() throws Exception {
    ZipPath nonPbFile = ZipPath.create("manifest/AndroidManifest.dat");
    InvalidBundleException e = assertThrows(InvalidBundleException.class, () -> new BundleFilesValidator().validateModuleFile(nonPbFile));
    assertThat(e).hasMessageThat().contains("Only 'AndroidManifest.xml' is accepted under directory 'manifest/' but found file " + "'manifest/AndroidManifest.dat'");
}
Also used : InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) ZipPath(com.android.tools.build.bundletool.model.ZipPath) Test(org.junit.Test)

Aggregations

ZipPath (com.android.tools.build.bundletool.model.ZipPath)194 Test (org.junit.Test)154 BuildApksResult (com.android.bundle.Commands.BuildApksResult)106 Path (java.nio.file.Path)55 DeviceSpec (com.android.bundle.Devices.DeviceSpec)44 InvalidBundleException (com.android.tools.build.bundletool.model.exceptions.InvalidBundleException)23 ImmutableSet (com.google.common.collect.ImmutableSet)23 ModuleEntry (com.android.tools.build.bundletool.model.ModuleEntry)19 Variant (com.android.bundle.Commands.Variant)16 ApksArchiveHelpers.createVariant (com.android.tools.build.bundletool.testing.ApksArchiveHelpers.createVariant)15 BundleModule (com.android.tools.build.bundletool.model.BundleModule)13 ImmutableList (com.google.common.collect.ImmutableList)12 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)11 ApksArchiveHelpers.standaloneVariant (com.android.tools.build.bundletool.testing.ApksArchiveHelpers.standaloneVariant)10 Theory (org.junit.experimental.theories.Theory)10 AdbServer (com.android.tools.build.bundletool.device.AdbServer)9 IOException (java.io.IOException)9 ModuleSplit (com.android.tools.build.bundletool.model.ModuleSplit)8 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)8 UncheckedIOException (java.io.UncheckedIOException)8