use of com.android.tools.build.bundletool.io.ZipBuilder in project bundletool by google.
the class MandatoryFilesPresenceValidatorTest method bundleZipFile_withoutAndroidManifestInModule_throws.
@Test
public void bundleZipFile_withoutAndroidManifestInModule_throws() throws Exception {
Path bundlePath = new ZipBuilder().addFileWithContent(ZipPath.create("base/assets/file.txt"), DUMMY_CONTENT).addFileWithContent(ZipPath.create("BundleConfig.pb"), DUMMY_CONTENT).writeTo(tempFolder.resolve("bundle.aab"));
try (ZipFile bundleZip = new ZipFile(bundlePath.toFile())) {
InvalidBundleException exception = assertThrows(InvalidBundleException.class, () -> new MandatoryFilesPresenceValidator(AppBundle.NON_MODULE_DIRECTORIES).validateBundleZipFile(bundleZip));
assertThat(exception).hasMessageThat().contains("Module 'base' is missing mandatory file 'manifest/AndroidManifest.xml'");
}
}
use of com.android.tools.build.bundletool.io.ZipBuilder in project bundletool by google.
the class MandatoryFilesPresenceValidatorTest method moduleZipFile_withoutAndroidManifest_throws.
@Test
public void moduleZipFile_withoutAndroidManifest_throws() throws Exception {
Path modulePath = new ZipBuilder().addFileWithContent(ZipPath.create("assets/file.txt"), DUMMY_CONTENT).writeTo(tempFolder.resolve("base.zip"));
try (ZipFile moduleZip = new ZipFile(modulePath.toFile())) {
InvalidBundleException exception = assertThrows(InvalidBundleException.class, () -> new MandatoryFilesPresenceValidator(AppBundle.NON_MODULE_DIRECTORIES).validateModuleZipFile(moduleZip));
assertThat(exception).hasMessageThat().contains("Module 'base' is missing mandatory file 'manifest/AndroidManifest.xml'");
}
}
use of com.android.tools.build.bundletool.io.ZipBuilder in project bundletool by google.
the class AppBundleTest method createBasicZipBuilder.
private static ZipBuilder createBasicZipBuilder(BundleConfig config) {
ZipBuilder zipBuilder = new ZipBuilder();
zipBuilder.addFileWithContent(ZipPath.create("BundleConfig.pb"), config.toByteArray());
return zipBuilder;
}
use of com.android.tools.build.bundletool.io.ZipBuilder in project bundletool by google.
the class ApkSizeUtilsTest method multipleVariants_withUncompressedEntries.
@Test
public void multipleVariants_withUncompressedEntries() throws Exception {
ZipPath apkOne = ZipPath.create("apk_one.apk");
ZipPath apkTwo = ZipPath.create("apk_two.apk");
ImmutableList<Variant> variants = ImmutableList.of(createVariantForSingleSplitApk(variantSdkTargeting(sdkVersionFrom(21), ImmutableSet.of(sdkVersionFrom(23))), ApkTargeting.getDefaultInstance(), apkOne), createVariantForSingleSplitApk(variantSdkTargeting(sdkVersionFrom(23), ImmutableSet.of(sdkVersionFrom(21))), ApkTargeting.getDefaultInstance(), apkTwo));
ZipBuilder archiveBuilder = new ZipBuilder();
archiveBuilder.addFileWithContent(ZipPath.create(apkOne.toString()), DUMMY_BYTES);
archiveBuilder.addFileWithContent(ZipPath.create(apkTwo.toString()), DUMMY_BYTES, // APK stored uncompressed in the APKs zip.
EntryOption.UNCOMPRESSED);
archiveBuilder.addFileWithProtoContent(ZipPath.create("toc.pb"), BuildApksResult.newBuilder().addAllVariant(variants).build());
Path apksArchiveFile = archiveBuilder.writeTo(tmpDir.resolve("bundle.apks"));
ImmutableMap<String, Long> sizeByApkPaths = getVariantCompressedSizeByApkPaths(variants, apksArchiveFile);
assertThat(sizeByApkPaths.keySet()).containsExactly("apk_one.apk", "apk_two.apk");
long apkOneSize = sizeByApkPaths.get("apk_one.apk");
long apkTwoSize = sizeByApkPaths.get("apk_two.apk");
// Apks should have size at least 20. Gzip Header(10 bytes), deflated data (Min 2 Bytes for
// empty file), 8 bytes footer.
assertThat(apkOneSize).isGreaterThan(20L);
assertThat(apkTwoSize).isGreaterThan(20L);
assertThat(apkOneSize).isEqualTo(apkTwoSize);
}
use of com.android.tools.build.bundletool.io.ZipBuilder in project bundletool by google.
the class BuildBundleCommandTest method assetsTargeting_generated.
@Test
public void assetsTargeting_generated() throws Exception {
XmlNode manifest = androidManifest(PKG_NAME, withHasCode(true));
Assets assetsConfig = Assets.newBuilder().addDirectory(TargetedAssetsDirectory.newBuilder().setPath("assets").setTargeting(AssetsDirectoryTargeting.getDefaultInstance())).addDirectory(TargetedAssetsDirectory.newBuilder().setPath("assets/texture#tcf_atc/device#tier_0").setTargeting(mergeAssetsTargeting(assetsDirectoryTargeting(textureCompressionTargeting(TextureCompressionFormatAlias.ATC)), assetsDirectoryTargeting(deviceTierTargeting(0))))).build();
Path module = new ZipBuilder().addFileWithContent(ZipPath.create("assets/anything.dat"), "any".getBytes(UTF_8)).addFileWithContent(ZipPath.create("assets/texture#tcf_atc/device#tier_0/file.dat"), "any2".getBytes(UTF_8)).addFileWithContent(ZipPath.create("dex/classes.dex"), "dex".getBytes(UTF_8)).addFileWithProtoContent(ZipPath.create("manifest/AndroidManifest.xml"), manifest).writeTo(tmpDir.resolve("base.zip"));
BuildBundleCommand.builder().setOutputPath(bundlePath).setModulesPaths(ImmutableList.of(module)).build().execute();
try (ZipFile bundle = new ZipFile(bundlePath.toFile())) {
assertThat(bundle).hasFile("base/assets/anything.dat").withContent("any".getBytes(UTF_8));
assertThat(bundle).hasFile("base/assets/texture#tcf_atc/device#tier_0/file.dat").withContent("any2".getBytes(UTF_8));
assertThat(bundle).hasFile("base/dex/classes.dex").withContent("dex".getBytes(UTF_8));
assertThat(bundle).hasFile("base/manifest/AndroidManifest.xml").withContent(manifest.toByteArray());
assertThat(bundle).hasFile("base/assets.pb").withContent(assetsConfig.toByteArray());
}
}
Aggregations