use of com.android.tools.build.bundletool.io.ZipBuilder in project bundletool by google.
the class SdkBundleHasOneModuleValidatorTest method sdkBundleZipFile_multipleModules_throws.
@Test
public void sdkBundleZipFile_multipleModules_throws() throws Exception {
Path bundlePath = new ZipBuilder().addFileWithContent(ZipPath.create("BundleConfig.pb"), DUMMY_CONTENT).addFileWithContent(ZipPath.create("base/manifest/AndroidManifest.xml"), DUMMY_CONTENT).addFileWithContent(ZipPath.create("feature/manifest/AndroidManifest.xml"), DUMMY_CONTENT).writeTo(tempFolder.resolve("bundle.asb"));
try (ZipFile bundleZip = new ZipFile(bundlePath.toFile())) {
InvalidBundleException exception = assertThrows(InvalidBundleException.class, () -> new SdkBundleHasOneModuleValidator().validateBundleZipFile(bundleZip));
assertThat(exception).hasMessageThat().contains("SDK bundles need exactly one module");
}
}
use of com.android.tools.build.bundletool.io.ZipBuilder in project bundletool by google.
the class ValidatorRunnerTest method validateBundle_invokesRightSubValidatorMethods.
@Test
public void validateBundle_invokesRightSubValidatorMethods() throws Exception {
Path bundlePath = new ZipBuilder().addFileWithContent(ZipPath.create("BundleConfig.pb"), BUNDLE_CONFIG.toByteArray()).addFileWithProtoContent(ZipPath.create("moduleX/manifest/AndroidManifest.xml"), androidManifest("com.test.app", withSplitId("moduleX"))).addFileWithProtoContent(ZipPath.create("moduleX/assets.pb"), Assets.getDefaultInstance()).addFileWithProtoContent(ZipPath.create("moduleX/native.pb"), NativeLibraries.getDefaultInstance()).addFileWithProtoContent(ZipPath.create("moduleX/resources.pb"), ResourceTable.getDefaultInstance()).addFileWithContent(ZipPath.create("moduleX/res/drawable/icon.png"), DUMMY_CONTENT).addFileWithContent(ZipPath.create("moduleX/lib/x86/libX.so"), DUMMY_CONTENT).addFileWithProtoContent(ZipPath.create("moduleY/manifest/AndroidManifest.xml"), androidManifest("com.test.app", withSplitId("moduleY"))).addFileWithContent(ZipPath.create("moduleY/assets/file.txt"), DUMMY_CONTENT).writeTo(tempFolder.resolve("bundle.aab"));
try (ZipFile bundleZip = new ZipFile(bundlePath.toFile())) {
AppBundle bundle = AppBundle.buildFromZip(bundleZip);
ImmutableList<BundleModule> bundleFeatureModules = ImmutableList.copyOf(bundle.getFeatureModules().values());
new ValidatorRunner(ImmutableList.of(validator)).validateBundle(bundle);
ArgumentCaptor<BundleModule> moduleArgs = ArgumentCaptor.forClass(BundleModule.class);
ArgumentCaptor<ZipPath> fileArgs = ArgumentCaptor.forClass(ZipPath.class);
verify(validator).validateBundle(eq(bundle));
verify(validator).validateAllModules(eq(bundleFeatureModules));
verify(validator, times(2)).validateModule(moduleArgs.capture());
verify(validator, atLeastOnce()).validateModuleFile(fileArgs.capture());
verifyNoMoreInteractions(validator);
assertThat(moduleArgs.getAllValues()).containsExactlyElementsIn(bundle.getFeatureModules().values());
assertThat(fileArgs.getAllValues().stream().map(ZipPath::toString)).containsExactly("assets/file.txt", "lib/x86/libX.so", "res/drawable/icon.png");
}
}
use of com.android.tools.build.bundletool.io.ZipBuilder in project bundletool by google.
the class ZipUtilsTest method createZipFileWithFiles.
private ZipFile createZipFileWithFiles(String... fileNames) throws IOException {
ZipBuilder zipBuilder = new ZipBuilder();
for (String fileName : fileNames) {
zipBuilder.addFileWithContent(ZipPath.create(fileName), fileName.getBytes(UTF_8));
}
Path zipPath = zipBuilder.writeTo(tmp.getRoot().toPath().resolve("output.jar"));
return new ZipFile(zipPath.toFile());
}
use of com.android.tools.build.bundletool.io.ZipBuilder in project bundletool by google.
the class BuildApksCommandTest method sdkBundleZipMissingManifest_sdkBundleZipFileValidationFails.
@Test
public void sdkBundleZipMissingManifest_sdkBundleZipFileValidationFails() throws Exception {
new ZipBuilder().addFileWithContent(ZipPath.create("base/dex/classes.dex"), new byte[1]).addFileWithContent(ZipPath.create("BundleConfig.pb"), new byte[1]).writeTo(sdkBundlePath1);
createAppBundle(bundlePath);
BuildApksCommand command = BuildApksCommand.fromFlags(new FlagParser().parse("--bundle=" + bundlePath, "--output=" + outputFilePath, "--sdk-bundles=" + sdkBundlePath1), fakeAdbServer);
Exception e = assertThrows(InvalidBundleException.class, command::execute);
assertThat(e).hasMessageThat().contains("Module 'base' is missing mandatory file 'manifest/AndroidManifest.xml'.");
}
Aggregations