use of com.android.tools.build.bundletool.model.ZipPath in project bundletool by google.
the class TargetedDirectoryTest method upperCaseNames_ok.
@Test
public void upperCaseNames_ok() {
ZipPath path = ZipPath.create("assets/world/gFX#lang_en/TEXTURE#tcf_etc1");
TargetedDirectory actual = TargetedDirectory.parse(path);
assertThat(actual.getPathSegments()).hasSize(4);
assertThat(actual.getPathSegments().get(0).getName()).isEqualTo("assets");
assertThat(actual.getPathSegments().get(0).getTargeting()).isEqualTo(AssetsDirectoryTargeting.getDefaultInstance());
assertThat(actual.getPathSegments().get(1).getName()).isEqualTo("world");
assertThat(actual.getPathSegments().get(1).getTargeting()).isEqualTo(AssetsDirectoryTargeting.getDefaultInstance());
assertThat(actual.getPathSegments().get(2).getName()).isEqualTo("gFX");
assertThat(actual.getPathSegments().get(2).getTargeting()).isEqualTo(assetsDirectoryTargeting(languageTargeting("en")));
assertThat(actual.getPathSegments().get(3).getName()).isEqualTo("TEXTURE");
assertThat(actual.getPathSegments().get(3).getTargeting()).isEqualTo(assetsDirectoryTargeting(textureCompressionTargeting(TextureCompressionFormatAlias.ETC1_RGB8)));
}
use of com.android.tools.build.bundletool.model.ZipPath in project bundletool by google.
the class ApkSizeUtilsTest method oneLVariant.
@Test
public void oneLVariant() throws Exception {
ZipPath apkOne = ZipPath.create("apk_one.apk");
ImmutableList<Variant> variants = ImmutableList.of(createVariantForSingleSplitApk(variantSdkTargeting(sdkVersionFrom(21)), ApkTargeting.getDefaultInstance(), apkOne));
Path apksArchiveFile = createApksArchiveFile(BuildApksResult.newBuilder().addAllVariant(variants).build(), tmpDir.resolve("bundle.apks"));
ImmutableMap<String, Long> sizeByApkPaths = getVariantCompressedSizeByApkPaths(variants, apksArchiveFile);
assertThat(sizeByApkPaths.keySet()).containsExactly("apk_one.apk");
assertThat(sizeByApkPaths.get("apk_one.apk")).isAtLeast(1L);
}
use of com.android.tools.build.bundletool.model.ZipPath in project bundletool by google.
the class ModuleSplitSerializer method serialize.
/**
* Serializes module splits on disk under {@code outputDirectory}.
*
* <p>Returns {@link ApkDescription} for each serialized split keyed by relative path of module
* split.
*/
public ImmutableMap<ZipPath, ApkDescription> serialize(Path outputDirectory, ImmutableMap<ZipPath, ModuleSplit> splitsByRelativePath) {
// Prepare original splits by:
// * signing embedded APKs
// * injecting manifest and resource table as module entries.
ImmutableList<ModuleSplit> preparedSplits = splitsByRelativePath.values().stream().map(apkSigner::signEmbeddedApks).map(ModuleSplitSerializer::injectManifestAndResourceTableAsEntries).collect(toImmutableList());
try (SerializationFilesManager filesManager = new SerializationFilesManager()) {
// Convert module splits to binary format and apply uncompressed globs specified in
// BundleConfig. We do it in this order because as specified in documentation the matching
// for uncompressed globs is done against paths in final APKs.
ImmutableList<ModuleSplit> binarySplits = aapt2ResourceConverter.convert(preparedSplits, filesManager).stream().map(this::applyUncompressedGlobsAndUncompressedNativeLibraries).collect(toImmutableList());
// Build a pack from entries which may be compressed inside final APKs. 'May be
// compressed' means that for these entries we will decide later should they be compressed
// or not based on whether we gain enough savings from compression.
ModuleEntriesPack maybeCompressedEntriesPack = buildCompressedEntriesPack(filesManager.getCompressedResourceEntriesPackPath(), filesManager.getCompressedEntriesPackPath(), binarySplits);
// Build a pack with entries that are uncompressed in final APKs: force uncompressed entries
// + entries that have very low compression ratio.
ModuleEntriesPack uncompressedEntriesPack = buildUncompressedEntriesPack(filesManager.getUncompressedEntriesPackPath(), binarySplits, maybeCompressedEntriesPack);
// Now content of all binary apks is already moved to compressed/uncompressed packs. Delete
// them to free space.
filesManager.closeAndRemoveBinaryApks();
// Merge two packs together, so we have all entries for final APKs inside one pack. If the
// same entry is in both packs we prefer uncompressed one, because it means this entry
// has very low compression ratio, it makes no sense to put it in compressed form.
ModuleEntriesPack allEntriesPack = maybeCompressedEntriesPack.mergeWith(uncompressedEntriesPack);
// Serialize and sign final APKs.
ImmutableList<ListenableFuture<ApkDescription>> apkDescriptions = Streams.zip(splitsByRelativePath.keySet().stream(), binarySplits.stream(), (relativePath, split) -> executorService.submit(() -> serializeAndSignSplit(outputDirectory, relativePath, split, allEntriesPack, uncompressedEntriesPack))).collect(toImmutableList());
return ConcurrencyUtils.waitForAll(apkDescriptions).stream().collect(toImmutableMap(apk -> ZipPath.create(apk.getPath()), identity()));
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
use of com.android.tools.build.bundletool.model.ZipPath in project bundletool by google.
the class ModuleSplitSerializer method serializeAndSignSplit.
private ApkDescription serializeAndSignSplit(Path outputDirectory, ZipPath apkRelativePath, ModuleSplit split, ModuleEntriesPack allEntriesPack, ModuleEntriesPack uncompressedEntriesPack) {
Path outputPath = outputDirectory.resolve(apkRelativePath.toString());
ApkDescription apkDescription = ApkDescriptionHelper.createApkDescription(apkRelativePath, split);
serializeSplit(outputPath, split, allEntriesPack, uncompressedEntriesPack);
apkSigner.signApk(outputPath, split);
notifyApkSerialized(apkDescription, split.getSplitType());
return apkDescription;
}
use of com.android.tools.build.bundletool.model.ZipPath in project bundletool by google.
the class ModuleSplitSerializer method serializeSplit.
private void serializeSplit(Path outputPath, ModuleSplit split, ModuleEntriesPack allEntriesPack, ModuleEntriesPack uncompressedEntriesPack) {
FileUtils.createDirectories(outputPath.getParent());
try (ZipArchive archive = new ZipArchive(outputPath)) {
ImmutableMap<ZipPath, ModuleEntry> moduleEntriesByName = split.getEntries().stream().collect(toImmutableMap(entry -> toApkEntryPath(entry.getPath()), entry -> entry, // e.g. base/assets/foo and base/root/assets/foo.
(a, b) -> b));
// Sorting entries by name for determinism.
ImmutableList<ModuleEntry> sortedEntries = ImmutableList.sortedCopyOf(Comparator.comparing(e -> toApkEntryPath(e.getPath())), moduleEntriesByName.values());
ZipSource zipSource = allEntriesPack.select(sortedEntries, entry -> toApkEntryPath(entry.getPath(), /* binaryApk= */
true).toString(), entry -> alignmentForEntry(entry, uncompressedEntriesPack));
archive.add(zipSource);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
Aggregations