use of com.android.tools.build.bundletool.io.ZipBuilder in project bundletool by google.
the class BuildBundleCommandTest method directoryZipEntriesInModuleFiles_notIncludedInBundle.
@Test
public void directoryZipEntriesInModuleFiles_notIncludedInBundle() throws Exception {
Path tmpBaseModulePath = Files.move(buildSimpleModule("base"), tmpDir.resolve("base.zip.tmp"));
Path baseModulePath;
// Copy the valid bundle, only add a directory zip entry.
try (ZipFile tmpBaseModuleZip = new ZipFile(tmpBaseModulePath.toFile())) {
baseModulePath = new ZipBuilder().copyAllContentsFromZip(ZipPath.create(""), tmpBaseModuleZip).addDirectory(ZipPath.create("directory-entry")).writeTo(tmpDir.resolve("base.zip"));
}
BuildBundleCommand.builder().setOutputPath(bundlePath).setModulesPaths(ImmutableList.of(baseModulePath)).build().execute();
try (ZipFile bundleZip = new ZipFile(bundlePath.toFile())) {
assertThat(Collections.list(bundleZip.entries()).stream().filter(ZipEntry::isDirectory)).isEmpty();
}
}
use of com.android.tools.build.bundletool.io.ZipBuilder in project bundletool by google.
the class GetSizeCommandTest method getSizeTotalInternal_singleSplitVariant.
@Test
public void getSizeTotalInternal_singleSplitVariant() throws Exception {
Variant lVariant = createVariant(lPlusVariantTargeting(), createSplitApkSet(/* moduleName= */
"base", createMasterApkDescription(ApkTargeting.getDefaultInstance(), ZipPath.create("base-master.apk")), createApkDescription(apkAbiTargeting(X86, ImmutableSet.of(X86_64)), ZipPath.create("base-x86.apk"), /* isMasterSplit= */
false), createApkDescription(apkAbiTargeting(X86_64, ImmutableSet.of(X86)), ZipPath.create("base-x86_64.apk"), /* isMasterSplit= */
false)));
ZipBuilder archiveBuilder = new ZipBuilder();
archiveBuilder.addFileWithContent(ZipPath.create("base-master.apk"), DUMMY_BYTES);
archiveBuilder.addFileWithContent(ZipPath.create("base-x86.apk"), DUMMY_BYTES, // APK stored uncompressed in the APKs zip.
EntryOption.UNCOMPRESSED);
archiveBuilder.addFileWithContent(ZipPath.create("base-x86_64.apk"), new byte[10000]);
archiveBuilder.addFileWithProtoContent(ZipPath.create("toc.pb"), BuildApksResult.newBuilder().setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(lVariant).build());
Path apksArchiveFile = archiveBuilder.writeTo(tmpDir.resolve("bundle.apks"));
ConfigurationSizes configurationSizes = GetSizeCommand.builder().setGetSizeSubCommand(GetSizeSubcommand.TOTAL).setApksArchivePath(apksArchiveFile).build().getSizeTotalInternal();
assertThat(configurationSizes.getMinSizeConfigurationMap().keySet()).containsExactly(SizeConfiguration.getDefaultInstance());
assertThat(configurationSizes.getMinSizeConfigurationMap().get(SizeConfiguration.getDefaultInstance())).isEqualTo(// base+x86
2 * compressedApkSize);
assertThat(configurationSizes.getMaxSizeConfigurationMap().keySet()).containsExactly(SizeConfiguration.getDefaultInstance());
assertThat(configurationSizes.getMaxSizeConfigurationMap().get(SizeConfiguration.getDefaultInstance())).isGreaterThan(// base+x86_64
2 * compressedApkSize);
}
use of com.android.tools.build.bundletool.io.ZipBuilder in project bundletool by google.
the class GetSizeCommandTest method getSizeTotalInternal_withNoDimensionsAndDeviceSpec.
@Test
public void getSizeTotalInternal_withNoDimensionsAndDeviceSpec() throws Exception {
Variant lVariant = createVariant(lPlusVariantTargeting(), createSplitApkSet(/* moduleName= */
"base", createMasterApkDescription(ApkTargeting.getDefaultInstance(), ZipPath.create("base-master.apk"))));
Variant preLVariant = standaloneVariant(mergeVariantTargeting(variantSdkTargeting(sdkVersionFrom(1), ImmutableSet.of(sdkVersionFrom(21))), variantAbiTargeting(X86, ImmutableSet.of(ARMEABI_V7A, ARM64_V8A))), ApkTargeting.getDefaultInstance(), ZipPath.create("preL.apk"));
ZipBuilder archiveBuilder = new ZipBuilder();
archiveBuilder.addFileWithContent(ZipPath.create("base-master.apk"), DUMMY_BYTES);
archiveBuilder.addFileWithContent(ZipPath.create("preL.apk"), new byte[10000]);
archiveBuilder.addFileWithProtoContent(ZipPath.create("toc.pb"), BuildApksResult.newBuilder().setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(lVariant).addVariant(preLVariant).build());
Path apksArchiveFile = archiveBuilder.writeTo(tmpDir.resolve("bundle.apks"));
ConfigurationSizes configurationSizes = GetSizeCommand.builder().setGetSizeSubCommand(GetSizeSubcommand.TOTAL).setApksArchivePath(apksArchiveFile).setDeviceSpec(DeviceSpec.newBuilder().setSdkVersion(21).build()).build().getSizeTotalInternal();
assertThat(configurationSizes.getMinSizeConfigurationMap()).containsExactly(SizeConfiguration.getDefaultInstance(), // only split apk
compressedApkSize);
assertThat(configurationSizes.getMaxSizeConfigurationMap()).containsExactly(SizeConfiguration.getDefaultInstance(), // only split apk
compressedApkSize);
}
use of com.android.tools.build.bundletool.io.ZipBuilder in project bundletool by google.
the class BuildBundleCommandTest method runsModuleDependencyValidator_cycle_throws.
@Test
public void runsModuleDependencyValidator_cycle_throws() throws Exception {
Path baseModulePath = new ZipBuilder().addFileWithProtoContent(ZipPath.create("manifest/AndroidManifest.xml"), androidManifest(PKG_NAME)).writeTo(tmpDir.resolve("base.zip"));
Path module1Path = new ZipBuilder().addFileWithProtoContent(ZipPath.create("manifest/AndroidManifest.xml"), androidManifest(PKG_NAME, withSplitId("module1"), withUsesSplit("module2"), withOnDemandAttribute(false), withFusingAttribute(true))).writeTo(tmpDir.resolve("module1.zip"));
Path module2Path = new ZipBuilder().addFileWithProtoContent(ZipPath.create("manifest/AndroidManifest.xml"), androidManifest(PKG_NAME, withSplitId("module2"), withUsesSplit("module3"), withOnDemandAttribute(false), withFusingAttribute(true))).writeTo(tmpDir.resolve("module2.zip"));
Path module3Path = new ZipBuilder().addFileWithProtoContent(ZipPath.create("manifest/AndroidManifest.xml"), androidManifest(PKG_NAME, withSplitId("module3"), withUsesSplit("module1"), withOnDemandAttribute(false), withFusingAttribute(true))).writeTo(tmpDir.resolve("module3.zip"));
BuildBundleCommand command = BuildBundleCommand.builder().setOutputPath(bundlePath).setModulesPaths(ImmutableList.of(baseModulePath, module1Path, module2Path, module3Path)).build();
InvalidBundleException exception = assertThrows(InvalidBundleException.class, command::execute);
assertThat(exception).hasMessageThat().contains("Found cyclic dependency between modules");
}
use of com.android.tools.build.bundletool.io.ZipBuilder in project bundletool by google.
the class BuildBundleCommandTest method nativeLibrariesPresent_abiTargetingIsPresent.
@Test
public void nativeLibrariesPresent_abiTargetingIsPresent() throws Exception {
Path moduleWithAbi = new ZipBuilder().addFileWithContent(ZipPath.create("lib/x86/libfast.so"), "native data".getBytes(UTF_8)).addFileWithContent(ZipPath.create("lib/x86/libfaster.so"), "native data".getBytes(UTF_8)).addFileWithProtoContent(ZipPath.create("manifest/AndroidManifest.xml"), androidManifest(PKG_NAME)).writeTo(tmpDir.resolve("base.zip"));
BuildBundleCommand.builder().setOutputPath(bundlePath).setModulesPaths(ImmutableList.of(moduleWithAbi)).build().execute();
NativeLibraries actualTargeting;
try (ZipFile bundle = new ZipFile(bundlePath.toFile())) {
assertThat(bundle).hasFile("base/native.pb");
actualTargeting = NativeLibraries.parseFrom(bundle.getInputStream(new ZipEntry("base/native.pb")));
}
NativeLibraries expectedTargeting = NativeLibraries.newBuilder().addDirectory(TargetedNativeDirectory.newBuilder().setPath("lib/x86").setTargeting(NativeDirectoryTargeting.newBuilder().setAbi(Abi.newBuilder().setAlias(X86)))).build();
Truth.assertThat(actualTargeting).isEqualTo(expectedTargeting);
}
Aggregations