use of com.android.bundle.Commands.ApkSet in project bundletool by google.
the class BuildApksManagerTest method buildApksCommand_splitApks_twoModulesOneOnDemand.
@Test
public void buildApksCommand_splitApks_twoModulesOneOnDemand() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.addFile("dex/classes.dex").setManifest(androidManifest("com.test.app")).setResourceTable(resourceTableWithTestLabel("Test feature"))).addModule("onDemand", builder -> builder.setManifest(androidManifest("com.test.app", withOnDemandAttribute(true), withTitle("@string/test_label", TEST_LABEL_RESOURCE_ID), withFusingAttribute(true)))).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
assertThat(splitApkVariants(result)).hasSize(1);
Variant splitApkVariant = splitApkVariants(result).get(0);
ImmutableMap<String, ApkSet> splitApkSetByModuleName = Maps.uniqueIndex(splitApkVariant.getApkSetList(), apkSet -> apkSet.getModuleMetadata().getName());
assertThat(splitApkSetByModuleName).hasSize(2);
ApkSet baseSplits = splitApkSetByModuleName.get("base");
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());
ApkSet onDemandSplits = splitApkSetByModuleName.get("onDemand");
assertThat(onDemandSplits.getModuleMetadata().getName()).isEqualTo("onDemand");
assertThat(onDemandSplits.getModuleMetadata().getDeliveryType()).isEqualTo(DeliveryType.ON_DEMAND);
assertThat(onDemandSplits.getApkDescriptionList()).hasSize(1);
assertThat(apkSetFile).hasFile(onDemandSplits.getApkDescription(0).getPath());
}
use of com.android.bundle.Commands.ApkSet in project bundletool by google.
the class BuildApksManagerTest method buildApksCommand_system_withoutLanguageTargeting.
@Test
@Theory
public void buildApksCommand_system_withoutLanguageTargeting() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.addFile("dex/classes.dex").addFile("lib/x86/libsome.so").addFile("lib/x86_64/libsome.so").addFile("lib/mips/libsome.so").setNativeConfig(nativeLibraries(targetedNativeDirectory("lib/x86", nativeDirectoryTargeting(X86)), targetedNativeDirectory("lib/x86_64", nativeDirectoryTargeting(X86_64)), targetedNativeDirectory("lib/mips", nativeDirectoryTargeting(MIPS)))).setManifest(androidManifest("com.test.app"))).setBundleConfig(BundleConfigBuilder.create().addSplitDimension(Value.ABI).addSplitDimension(Value.SCREEN_DENSITY, /* negate= */
true).build()).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).withApkBuildMode(SYSTEM).withDeviceSpec(mergeSpecs(sdkVersion(28), abis("mips"), density(DensityAlias.MDPI), locales("en-US"))).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
assertThat(result.getVariantList()).hasSize(1);
assertThat(splitApkVariants(result)).isEmpty();
assertThat(standaloneApkVariants(result)).isEmpty();
assertThat(systemApkVariants(result)).hasSize(1);
Variant systemVariant = systemApkVariants(result).get(0);
assertThat(systemVariant.getTargeting()).isEqualTo(mergeVariantTargeting(variantAbiTargeting(MIPS, ImmutableSet.of(X86, X86_64)), variantSdkTargeting(LOWEST_SDK_VERSION)));
assertThat(apkDescriptions(systemVariant)).hasSize(1);
assertThat(systemVariant.getApkSetList()).hasSize(1);
ApkSet apkSet = systemVariant.getApkSet(0);
apkSet.getApkDescriptionList().forEach(apkDescription -> assertThat(apkSetFile).hasFile(apkDescription.getPath()));
}
use of com.android.bundle.Commands.ApkSet in project bundletool by google.
the class BuildApksManagerTest method buildApksCommand_archive_success.
@Test
public void buildApksCommand_archive_success() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.setManifest(androidManifest("com.test.app"))).setBundleConfig(BundleConfigBuilder.create().setStoreArchive(true).build()).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).withApkBuildMode(ARCHIVE).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
assertThat(result.getVariantList()).hasSize(1);
assertThat(splitApkVariants(result)).isEmpty();
assertThat(standaloneApkVariants(result)).isEmpty();
assertThat(systemApkVariants(result)).isEmpty();
assertThat(archivedApkVariants(result)).hasSize(1);
Variant archivedVariant = archivedApkVariants(result).get(0);
assertThat(archivedVariant.getTargeting()).isEqualToDefaultInstance();
assertThat(apkDescriptions(archivedVariant)).hasSize(1);
assertThat(archivedVariant.getApkSetList()).hasSize(1);
ApkSet apkSet = archivedVariant.getApkSet(0);
assertThat(apkSet.getApkDescriptionList().stream().map(ApkDescription::getPath).collect(toImmutableSet())).containsExactly("archive/archive.apk");
apkSet.getApkDescriptionList().forEach(apkDescription -> assertThat(apkSetFile).hasFile(apkDescription.getPath()));
}
use of com.android.bundle.Commands.ApkSet 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.ApkSet in project bundletool by google.
the class BuildApksManagerTest method buildApksCommand_populatesDependencies.
@Test
public void buildApksCommand_populatesDependencies() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.setManifest(androidManifest("com.test.app"))).addModule("feature1", builder -> builder.setManifest(androidManifest("com.test.app", withOnDemandAttribute(false), withFusingAttribute(true)))).addModule("feature2", builder -> builder.setManifest(androidManifest("com.test.app", withUsesSplit("feature1"), withOnDemandAttribute(false), withFusingAttribute(true)))).addModule("feature3", builder -> builder.setManifest(androidManifest("com.test.app", withUsesSplit("feature1", "feature2"), withOnDemandAttribute(false), withFusingAttribute(true)))).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
// split APKs
assertThat(splitApkVariants(result)).hasSize(1);
Variant splitApkVariant = splitApkVariants(result).get(0);
ImmutableMap<String, ApkSet> splitApkSetByModuleName = Maps.uniqueIndex(splitApkVariant.getApkSetList(), apkSet -> apkSet.getModuleMetadata().getName());
assertThat(splitApkSetByModuleName).hasSize(4);
ApkSet baseSplits = splitApkSetByModuleName.get("base");
assertThat(baseSplits.getModuleMetadata().getDependenciesList()).isEmpty();
ApkSet feature1Splits = splitApkSetByModuleName.get("feature1");
assertThat(feature1Splits.getModuleMetadata().getDependenciesList()).isEmpty();
ApkSet feature2Splits = splitApkSetByModuleName.get("feature2");
assertThat(feature2Splits.getModuleMetadata().getDependenciesList()).containsExactly("feature1");
ApkSet feature3Splits = splitApkSetByModuleName.get("feature3");
assertThat(feature3Splits.getModuleMetadata().getDependenciesList()).containsExactly("feature1", "feature2");
// standalone APK
assertThat(standaloneApkVariants(result)).hasSize(1);
List<ApkSet> apkSetList = standaloneApkVariants(result).get(0).getApkSetList();
assertThat(apkSetList).hasSize(1);
assertThat(apkSetList.get(0).getModuleMetadata().getDependenciesList()).isEmpty();
}
Aggregations