use of com.android.bundle.Commands.ModuleMetadata in project bundletool by google.
the class BuildApksManagerTest method deviceGroupTargetedConditionalModule.
@Test
public void deviceGroupTargetedConditionalModule() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.setManifest(androidManifest("com.test")).setResourceTable(resourceTableWithTestLabel("Test feature"))).addModule("device_tier_feature", builder -> builder.setManifest(androidManifest("com.test", withTitle("@string/test_label", TEST_LABEL_RESOURCE_ID), withFusingAttribute(false), withDeviceGroupsCondition(ImmutableList.of("group1", "group2"))))).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
ModuleMetadata deviceTierModule = result.getVariantList().stream().flatMap(variant -> variant.getApkSetList().stream()).map(ApkSet::getModuleMetadata).filter(moduleMetadata -> moduleMetadata.getName().equals("device_tier_feature")).distinct().collect(onlyElement());
assertThat(deviceTierModule.getTargeting()).isEqualTo(moduleDeviceGroupsTargeting("group1", "group2"));
}
use of com.android.bundle.Commands.ModuleMetadata in project bundletool by google.
the class BuildApksManagerTest method selectsRightModules.
@Test
public void selectsRightModules() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", module -> module.addFile("assets/base.txt").setManifest(androidManifest("com.app")).setResourceTable(resourceTableWithTestLabel("Test feature"))).addModule("fused", module -> module.addFile("assets/fused.txt").setManifest(androidManifestForFeature("com.app", withFusingAttribute(true), withTitle("@string/test_label", TEST_LABEL_RESOURCE_ID)))).addModule("not_fused", module -> module.addFile("assets/not_fused.txt").setManifest(androidManifestForFeature("com.app", withFusingAttribute(false), withTitle("@string/test_label", TEST_LABEL_RESOURCE_ID)))).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
// Split APKs: All modules must be used.
ImmutableSet<String> modulesInSplitApks = splitApkVariants(result).stream().flatMap(variant -> variant.getApkSetList().stream()).map(ApkSet::getModuleMetadata).map(ModuleMetadata::getName).collect(toImmutableSet());
assertThat(modulesInSplitApks).containsExactly("base", "fused", "not_fused");
// Standalone APKs: Only base and modules marked for fusing must be used.
assertThat(standaloneApkVariants(result)).hasSize(1);
ImmutableList<ApkDescription> standaloneApks = apkDescriptions(standaloneApkVariants(result).get(0));
assertThat(standaloneApks).hasSize(1);
assertThat(standaloneApks.get(0).hasStandaloneApkMetadata()).isTrue();
assertThat(standaloneApks.get(0).getStandaloneApkMetadata().getFusedModuleNameList()).containsExactly("base", "fused");
File standaloneApkFile = extractFromApkSetFile(apkSetFile, standaloneApks.get(0).getPath(), outputDir);
// Validate that the standalone APK contains appropriate files.
ZipFile standaloneApkZip = openZipFile(standaloneApkFile);
assertThat(filesUnderPath(standaloneApkZip, ZipPath.create("assets"))).containsExactly("assets/base.txt", "assets/fused.txt");
}
Aggregations