use of com.android.bundle.Commands.AssetSliceSet in project bundletool by google.
the class AssetModuleSizeAggregatorTest method getSize_multipleAssetModules_withDeviceSpecAndVariantTargeting.
@Test
public void getSize_multipleAssetModules_withDeviceSpecAndVariantTargeting() throws Exception {
ImmutableList<AssetSliceSet> assetModules = ImmutableList.of(ASSET_MODULE_1, ASSET_MODULE_2);
VariantTargeting variantTargeting = variantTextureTargeting(ETC2);
ConfigurationSizes configurationSizes = new AssetModuleSizeAggregator(assetModules, variantTargeting, SIZE_BY_APK_PATHS, getSizeCommand.setDimensions(ImmutableSet.of(TEXTURE_COMPRESSION_FORMAT, SDK)).setDeviceSpec(sdkVersion(21)).build()).getSize();
assertThat(configurationSizes.getMinSizeConfigurationMap()).containsExactly(SizeConfiguration.builder().setTextureCompressionFormat("etc2").setSdkVersion("21").build(), ASSET_1_MASTER_SIZE + ASSET_1_ETC2_SIZE + ASSET_2_MASTER_SIZE + ASSET_2_ETC2_SIZE);
assertThat(configurationSizes.getMaxSizeConfigurationMap()).containsExactly(SizeConfiguration.builder().setTextureCompressionFormat("etc2").setSdkVersion("21").build(), ASSET_1_MASTER_SIZE + ASSET_1_ETC2_SIZE + ASSET_2_MASTER_SIZE + ASSET_2_ETC2_SIZE);
}
use of com.android.bundle.Commands.AssetSliceSet in project bundletool by google.
the class BuildApksManagerTest method buildApksCommand_assetOnly.
@Test
@Theory
public void buildApksCommand_assetOnly(@FromDataPoints("bundleVersion") Version bundleVersion) throws Exception {
AssetModulesConfig assetModulesConfig = AssetModulesConfig.newBuilder().setAssetVersionTag("qwe").addAppVersion(11).build();
AssetModulesInfo assetModulesInfo = AssetModulesInfo.newBuilder().setAssetVersionTag("qwe").addAppVersion(11).build();
AppBundle appBundle = new AppBundleBuilder().addModule("asset_module1", builder -> builder.setManifest(androidManifestForAssetModule("com.test.app", withOnDemandDelivery())).addFile("assets/images/image.jpg")).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withBundleConfig(BundleConfig.newBuilder().setAssetModulesConfig(assetModulesConfig).setType(BundleType.ASSET_ONLY)).withBundletoolVersion(bundleVersion.toString()).withOutputPath(outputFilePath).withCustomBuildApksCommandSetter(command -> command.setAssetModulesVersionOverride(123L)).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
// Variants
assertThat(splitApkVariants(result)).isEmpty();
// Asset Slices
List<AssetSliceSet> sliceSets = result.getAssetSliceSetList();
assertThat(sliceSets).hasSize(1);
AssetSliceSet assetSliceSet = sliceSets.get(0);
assertThat(assetSliceSet.getAssetModuleMetadata().hasInstantMetadata()).isTrue();
assertThat(assetSliceSet.getApkDescriptionList()).hasSize(1);
assertThat(apkSetFile).hasFile(assetSliceSet.getApkDescription(0).getPath());
ApkDescription apkDescription = assetSliceSet.getApkDescription(0);
assertThat(apkDescription.getPath()).isEqualTo(String.format("asset-slices/%s-master.apk", assetSliceSet.getAssetModuleMetadata().getName()));
assertThat(apkDescription.hasAssetSliceMetadata()).isTrue();
assertThat(apkDescription.getAssetSliceMetadata().getIsMasterSplit()).isTrue();
assertThat(result.getAssetModulesInfo()).isEqualTo(assetModulesInfo);
}
use of com.android.bundle.Commands.AssetSliceSet in project bundletool by google.
the class BuildApksManagerTest method buildApksCommand_featureAndAssetModules_generatesAssetSlices.
@Test
@Theory
public void buildApksCommand_featureAndAssetModules_generatesAssetSlices(@FromDataPoints("bundleVersion") Version bundleVersion) throws Exception {
AppBundle appBundle = createAppBundleBuilder(bundleVersion).addModule("base", builder -> builder.addFile("dex/classes.dex").setManifest(androidManifest("com.test.app", withMinSdkVersion(15), withMaxSdkVersion(27), withInstant(true))).setResourceTable(resourceTableWithTestLabel("Test feature"))).addModule("asset_module1", builder -> builder.setManifest(androidManifestForAssetModule("com.test.app", withInstallTimeDelivery())).addFile("assets/images/image.jpg")).addModule("asset_module2", builder -> builder.setManifest(androidManifestForAssetModule("com.test.app", withOnDemandDelivery(), withInstantOnDemandDelivery())).addFile("assets/images/image2.jpg")).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
// Variants
ImmutableList<Variant> variants = splitApkVariants(result);
assertThat(variants).hasSize(1);
Variant splitApkVariant = variants.get(0);
List<ApkSet> apks = splitApkVariant.getApkSetList();
assertThat(apks).hasSize(1);
ApkSet baseSplits = apks.get(0);
assertThat(baseSplits.getModuleMetadata().getName()).isEqualTo("base");
assertThat(baseSplits.getModuleMetadata().getDeliveryType()).isEqualTo(DeliveryType.INSTALL_TIME);
assertThat(baseSplits.getApkDescriptionList()).hasSize(1);
assertThat(apkSetFile).hasFile(baseSplits.getApkDescription(0).getPath());
// Asset Slices
List<AssetSliceSet> sliceSets = result.getAssetSliceSetList();
assertThat(sliceSets).hasSize(2);
for (AssetSliceSet slice : sliceSets) {
assertThat(slice.getAssetModuleMetadata().hasInstantMetadata()).isTrue();
assertThat(slice.getApkDescriptionList()).hasSize(1);
assertThat(apkSetFile).hasFile(slice.getApkDescription(0).getPath());
ApkDescription apkDescription = slice.getApkDescription(0);
assertThat(apkDescription.getPath()).isEqualTo(String.format("asset-slices/%s-master.apk", slice.getAssetModuleMetadata().getName()));
assertThat(apkDescription.hasAssetSliceMetadata()).isTrue();
assertThat(apkDescription.getAssetSliceMetadata().getIsMasterSplit()).isTrue();
}
ImmutableMap<String, AssetSliceSet> sliceSetsByName = Maps.uniqueIndex(sliceSets, set -> set.getAssetModuleMetadata().getName());
assertThat(sliceSetsByName.get("asset_module1").getAssetModuleMetadata().getInstantMetadata().getIsInstant()).isFalse();
assertThat(sliceSetsByName.get("asset_module1").getApkDescription(0).getTargeting()).isEqualTo(ApkTargeting.newBuilder().setSdkVersionTargeting(SdkVersionTargeting.newBuilder().addValue(SdkVersion.newBuilder().setMin(Int32Value.newBuilder().setValue(ANDROID_L_API_VERSION)))).build());
assertThat(sliceSetsByName.get("asset_module2").getApkDescription(0).getTargeting()).isEqualToDefaultInstance();
InstantMetadata.Builder instantMetadata = InstantMetadata.newBuilder().setIsInstant(true);
instantMetadata.setDeliveryType(DeliveryType.ON_DEMAND);
assertThat(sliceSetsByName.get("asset_module2").getAssetModuleMetadata().getInstantMetadata()).isEqualTo(instantMetadata.build());
}
use of com.android.bundle.Commands.AssetSliceSet in project bundletool by google.
the class BuildApksPreprocessingTest method buildApksCommand_overridesAssetModuleCompression.
@Test
public void buildApksCommand_overridesAssetModuleCompression() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", module -> module.addFile("dex/classes.dex", DUMMY_CONTENT).addFile("assets/images/image.jpg", DUMMY_CONTENT).setManifest(androidManifest("com.test.app", withMinSdkVersion(15), withMaxSdkVersion(27))).setResourceTable(resourceTableWithTestLabel("Test feature"))).addModule("asset_module", module -> module.setManifest(androidManifestForAssetModule("com.test.app", withInstallTimeDelivery())).addFile("assets/textures/texture.etc", DUMMY_CONTENT)).build();
new AppBundleSerializer().writeToDisk(appBundle, bundlePath);
BuildApksCommand command = BuildApksCommand.builder().setBundlePath(bundlePath).setOutputFile(outputFilePath).build();
command.execute();
try (ZipFile apkSetFile = new ZipFile(outputFilePath.toFile())) {
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
// Standalone variant.
ImmutableList<Variant> standaloneVariants = standaloneApkVariants(result);
assertThat(standaloneVariants).hasSize(1);
Variant standaloneVariant = standaloneVariants.get(0);
assertThat(standaloneVariant.getApkSetList()).hasSize(1);
ApkSet standaloneApk = standaloneVariant.getApkSet(0);
assertThat(standaloneApk.getApkDescriptionList()).hasSize(1);
assertThat(apkSetFile).hasFile(standaloneApk.getApkDescription(0).getPath());
File standaloneApkFile = extractFromApkSetFile(apkSetFile, standaloneApk.getApkDescription(0).getPath(), outputDir);
try (ZipFile apkZip = new ZipFile(standaloneApkFile)) {
assertThat(apkZip).hasFile("classes.dex").thatIsCompressed();
assertThat(apkZip).hasFile("assets/images/image.jpg").thatIsCompressed();
assertThat(apkZip).hasFile("assets/textures/texture.etc").thatIsUncompressed();
}
// L+ assets.
assertThat(result.getAssetSliceSetCount()).isEqualTo(1);
AssetSliceSet assetSlice = result.getAssetSliceSet(0);
assertThat(assetSlice.getApkDescriptionCount()).isEqualTo(1);
File apkFile = extractFromApkSetFile(apkSetFile, assetSlice.getApkDescription(0).getPath(), outputDir);
try (ZipFile apkZip = new ZipFile(apkFile)) {
assertThat(apkZip).hasFile("assets/textures/texture.etc").thatIsUncompressed();
}
}
}
Aggregations