use of com.android.tools.build.bundletool.io.ZipBuilder in project bundletool by google.
the class BuildBundleCommandTest method validApexModule.
@Test
public void validApexModule() throws Exception {
XmlNode manifest = androidManifest(PKG_NAME, withHasCode(false));
ImmutableSet<AbiAlias> targetedAbis = ImmutableSet.of(X86_64, X86, ARM64_V8A, ARMEABI_V7A);
ApexImages apexConfig = apexImages(targetedImageWithAlternatives("apex/x86_64.img", X86_64, targetedAbis), targetedImageWithAlternatives("apex/x86.img", X86, targetedAbis), targetedImageWithAlternatives("apex/arm64-v8a.img", ARM64_V8A, targetedAbis), targetedImageWithAlternatives("apex/armeabi-v7a.img", ARMEABI_V7A, targetedAbis));
byte[] apexManifest = "{\"name\": \"com.test.app\"}".getBytes(UTF_8);
Path module = new ZipBuilder().addFileWithContent(ZipPath.create("apex/x86_64.img"), "x86_64".getBytes(UTF_8)).addFileWithContent(ZipPath.create("apex/x86.img"), "x86".getBytes(UTF_8)).addFileWithContent(ZipPath.create("apex/arm64-v8a.img"), "arm64-v8a".getBytes(UTF_8)).addFileWithContent(ZipPath.create("apex/armeabi-v7a.img"), "armeabi-v7a".getBytes(UTF_8)).addFileWithProtoContent(ZipPath.create("manifest/AndroidManifest.xml"), manifest).addFileWithContent(ZipPath.create("root/apex_manifest.json"), apexManifest).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/manifest/AndroidManifest.xml").withContent(manifest.toByteArray());
assertThat(bundle).hasFile("base/apex/x86_64.img").withContent("x86_64".getBytes(UTF_8));
assertThat(bundle).hasFile("base/apex/x86.img").withContent("x86".getBytes(UTF_8));
assertThat(bundle).hasFile("base/apex/arm64-v8a.img").withContent("arm64-v8a".getBytes(UTF_8));
assertThat(bundle).hasFile("base/apex/armeabi-v7a.img").withContent("armeabi-v7a".getBytes(UTF_8));
assertThat(bundle).hasFile("base/root/apex_manifest.json").withContent(apexManifest);
assertThat(bundle).hasFile("base/apex.pb").withContent(apexConfig.toByteArray());
}
}
use of com.android.tools.build.bundletool.io.ZipBuilder in project bundletool by google.
the class BuildBundleCommandTest method validApexModuleWithBuildInfo.
@Test
public void validApexModuleWithBuildInfo() throws Exception {
XmlNode manifest = androidManifest(PKG_NAME, withHasCode(false));
ImmutableSet<AbiAlias> targetedAbis = ImmutableSet.of(X86_64, X86, ARM64_V8A, ARMEABI_V7A);
ApexImages apexConfig = apexImages(targetedImageWithBuildInfoAndAlternatives("apex/x86_64.img", "apex/x86_64.build_info.pb", X86_64, targetedAbis), targetedImageWithBuildInfoAndAlternatives("apex/x86.img", "apex/x86.build_info.pb", X86, targetedAbis), targetedImageWithBuildInfoAndAlternatives("apex/arm64-v8a.img", "apex/arm64-v8a.build_info.pb", ARM64_V8A, targetedAbis), targetedImageWithBuildInfoAndAlternatives("apex/armeabi-v7a.img", "apex/armeabi-v7a.build_info.pb", ARMEABI_V7A, targetedAbis));
byte[] apexManifest = "{\"name\": \"com.test.app\"}".getBytes(UTF_8);
Path module = new ZipBuilder().addFileWithContent(ZipPath.create("apex/x86_64.img"), "x86_64".getBytes(UTF_8)).addFileWithContent(ZipPath.create("apex/x86_64.build_info.pb"), "x86_64.build_info".getBytes(UTF_8)).addFileWithContent(ZipPath.create("apex/x86.img"), "x86".getBytes(UTF_8)).addFileWithContent(ZipPath.create("apex/x86.build_info.pb"), "x86.build_info".getBytes(UTF_8)).addFileWithContent(ZipPath.create("apex/arm64-v8a.img"), "arm64-v8a".getBytes(UTF_8)).addFileWithContent(ZipPath.create("apex/arm64-v8a.build_info.pb"), "arm64-v8a.build_info".getBytes(UTF_8)).addFileWithContent(ZipPath.create("apex/armeabi-v7a.img"), "armeabi-v7a".getBytes(UTF_8)).addFileWithContent(ZipPath.create("apex/armeabi-v7a.build_info.pb"), "armeabi-v7a.build_info".getBytes(UTF_8)).addFileWithProtoContent(ZipPath.create("manifest/AndroidManifest.xml"), manifest).addFileWithContent(ZipPath.create("root/apex_manifest.json"), apexManifest).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/manifest/AndroidManifest.xml").withContent(manifest.toByteArray());
assertThat(bundle).hasFile("base/apex/x86_64.img").withContent("x86_64".getBytes(UTF_8));
assertThat(bundle).hasFile("base/apex/x86_64.build_info.pb").withContent("x86_64.build_info".getBytes(UTF_8));
assertThat(bundle).hasFile("base/apex/x86.img").withContent("x86".getBytes(UTF_8));
assertThat(bundle).hasFile("base/apex/x86.build_info.pb").withContent("x86.build_info".getBytes(UTF_8));
assertThat(bundle).hasFile("base/apex/arm64-v8a.img").withContent("arm64-v8a".getBytes(UTF_8));
assertThat(bundle).hasFile("base/apex/arm64-v8a.build_info.pb").withContent("arm64-v8a.build_info".getBytes(UTF_8));
assertThat(bundle).hasFile("base/apex/armeabi-v7a.img").withContent("armeabi-v7a".getBytes(UTF_8));
assertThat(bundle).hasFile("base/apex/armeabi-v7a.build_info.pb").withContent("armeabi-v7a.build_info".getBytes(UTF_8));
assertThat(bundle).hasFile("base/root/apex_manifest.json").withContent(apexManifest);
assertThat(bundle).hasFile("base/apex.pb").withContent(apexConfig.toByteArray());
}
}
use of com.android.tools.build.bundletool.io.ZipBuilder in project bundletool by google.
the class BuildBundleCommandTest method buildUncompressedBundle.
@Test
public void buildUncompressedBundle() throws Exception {
Path module = new ZipBuilder().addFileWithProtoContent(ZipPath.create("manifest/AndroidManifest.xml"), androidManifest(PKG_NAME)).addFileWithContent(ZipPath.create("dex/classes.dex"), new byte[8]).addFileWithContent(ZipPath.create("res/raw/hello.png"), new byte[8]).addFileWithProtoContent(ZipPath.create("resources.pb"), new ResourceTableBuilder().addPackage(PKG_NAME).addDrawableResource("hello", "res/raw/hello.png").build()).writeTo(tmpDir.resolve("base.zip"));
Path mainDexList = Files.createFile(tmp.getRoot().toPath().resolve("mainDexList.txt"));
BuildBundleCommand.builder().setModulesPaths(ImmutableList.of(module)).setOutputPath(bundlePath).setMainDexListFile(mainDexList).setUncompressedBundle(true).build().execute();
try (ZipFile bundle = new ZipFile(bundlePath.toFile())) {
Enumeration<? extends ZipEntry> entries = bundle.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
assertWithMessage("Entry %s is not uncompressed.", entry.getName()).that(entry.getMethod()).isEqualTo(ZipEntry.STORED);
}
}
}
use of com.android.tools.build.bundletool.io.ZipBuilder in project bundletool by google.
the class BuildBundleCommandTest method validModule.
@Test
public void validModule() throws Exception {
XmlNode manifest = androidManifest(PKG_NAME, withHasCode(true));
ResourceTable resourceTable = new ResourceTableBuilder().addPackage(PKG_NAME).addDrawableResource("icon", "res/drawable/icon.png").build();
Path module = new ZipBuilder().addFileWithContent(ZipPath.create("assets/anything.dat"), "any".getBytes(UTF_8)).addFileWithContent(ZipPath.create("dex/classes.dex"), "dex".getBytes(UTF_8)).addFileWithContent(ZipPath.create("lib/x86/libX.so"), "native".getBytes(UTF_8)).addFileWithProtoContent(ZipPath.create("manifest/AndroidManifest.xml"), manifest).addFileWithContent(ZipPath.create("res/drawable/icon.png"), "image".getBytes(UTF_8)).addFileWithContent(ZipPath.create("root/anything2.dat"), "any2".getBytes(UTF_8)).addFileWithProtoContent(ZipPath.create("resources.pb"), resourceTable).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/dex/classes.dex").withContent("dex".getBytes(UTF_8));
assertThat(bundle).hasFile("base/lib/x86/libX.so").withContent("native".getBytes(UTF_8));
assertThat(bundle).hasFile("base/manifest/AndroidManifest.xml").withContent(manifest.toByteArray());
assertThat(bundle).hasFile("base/res/drawable/icon.png").withContent("image".getBytes(UTF_8));
assertThat(bundle).hasFile("base/root/anything2.dat").withContent("any2".getBytes(UTF_8));
assertThat(bundle).hasFile("base/resources.pb").withContent(resourceTable.toByteArray());
}
}
use of com.android.tools.build.bundletool.io.ZipBuilder in project bundletool by google.
the class BuildBundleCommandTest method moduleWithWrongExtension_throws.
@Test
public void moduleWithWrongExtension_throws() throws Exception {
Path nonZipModule = new ZipBuilder().writeTo(tmpDir.resolve("not_a_zip.txt"));
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> BuildBundleCommand.builder().setOutputPath(bundlePath).setModulesPaths(ImmutableList.of(nonZipModule)).build().execute());
assertThat(exception).hasMessageThat().contains("expected to have '.zip' extension");
}
Aggregations