use of com.android.bundle.Commands.ApkSet in project bundletool by google.
the class BuildApksManagerTest method buildApksCommand_system_withLanguageTargeting.
@Test
@Theory
public void buildApksCommand_system_withLanguageTargeting() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.addFile("lib/x86/libsome.so").addFile("lib/x86_64/libsome.so").addFile("lib/mips/libsome.so").addFile("assets/languages#lang_es/image.jpg").addFile("assets/languages#lang_fr/image.jpg").addFile("assets/languages#lang_it/image.jpg").setResourceTable(new ResourceTableBuilder().addPackage("com.test.app").addStringResource("title", "Not fused").build()).setAssetsConfig(assets(targetedAssetsDirectory("assets/languages#lang_it", assetsDirectoryTargeting(languageTargeting("it"))), targetedAssetsDirectory("assets/languages#lang_es", assetsDirectoryTargeting(languageTargeting("es"))), targetedAssetsDirectory("assets/languages#lang_fr", assetsDirectoryTargeting(languageTargeting("fr"))))).setNativeConfig(nativeLibraries(targetedNativeDirectory("lib/x86", nativeDirectoryTargeting(X86)), targetedNativeDirectory("lib/x86_64", nativeDirectoryTargeting(X86_64)), targetedNativeDirectory("lib/mips", nativeDirectoryTargeting(MIPS)))).setManifest(androidManifest("com.test.app"))).addModule("not_fused", builder -> builder.addFile("lib/x86/libother.so").addFile("lib/x86_64/libother.so").addFile("lib/mips/libother.so").addFile("assets/other_languages#lang_es/image.jpg").addFile("assets/other_languages#lang_fr/image.jpg").addFile("assets/other_languages#lang_it/image.jpg").setAssetsConfig(assets(targetedAssetsDirectory("assets/other_languages#lang_it", assetsDirectoryTargeting(languageTargeting("it"))), targetedAssetsDirectory("assets/other_languages#lang_es", assetsDirectoryTargeting(languageTargeting("es"))), targetedAssetsDirectory("assets/other_languages#lang_fr", assetsDirectoryTargeting(languageTargeting("fr"))))).setNativeConfig(nativeLibraries(targetedNativeDirectory("lib/x86", nativeDirectoryTargeting(X86)), targetedNativeDirectory("lib/x86_64", nativeDirectoryTargeting(X86_64)), targetedNativeDirectory("lib/mips", nativeDirectoryTargeting(MIPS)))).setManifest(androidManifestForFeature("com.test.app", withTitle("Not fused", 0x7f010000), withFusingAttribute(false)))).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).withApkBuildMode(SYSTEM).withDeviceSpec(mergeSpecs(sdkVersion(28), abis("x86"), density(DensityAlias.MDPI), locales("es"))).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
assertThat(result.getVariantList()).hasSize(1);
Variant x86Variant = result.getVariant(0);
assertThat(x86Variant.getVariantNumber()).isEqualTo(0);
assertThat(x86Variant.getTargeting()).ignoringRepeatedFieldOrder().isEqualTo(mergeVariantTargeting(variantAbiTargeting(X86, ImmutableSet.of(X86_64, MIPS)), variantSdkTargeting(LOWEST_SDK_VERSION)));
assertThat(x86Variant.getApkSetList()).hasSize(2);
ApkSet apkSet = x86Variant.getApkSet(0);
assertThat(apkSet.getApkDescriptionList().stream().map(ApkDescription::getPath).collect(toImmutableSet())).containsExactly("system/system.apk", "splits/base-it.apk", "splits/base-fr.apk");
ApkSet apkSetNotFusedModule = x86Variant.getApkSet(1);
assertThat(apkSetNotFusedModule.getApkDescriptionList().stream().map(ApkDescription::getPath).collect(toImmutableSet())).containsExactly("splits/not_fused-master.apk", "splits/not_fused-es.apk", "splits/not_fused-it.apk", "splits/not_fused-fr.apk", "splits/not_fused-x86.apk");
apkSet.getApkDescriptionList().forEach(apkDescription -> assertThat(apkSetFile).hasFile(apkDescription.getPath()));
}
use of com.android.bundle.Commands.ApkSet in project bundletool by google.
the class BuildApksResourcePinningTest method resourceIds_pinnedToMasterSplits.
@Test
public void resourceIds_pinnedToMasterSplits() throws Exception {
ResourceTable baseResourceTable = new ResourceTableBuilder().addPackage("com.test.app").addStringResource("test_label", "Module title").addFileResourceForMultipleConfigs("drawable", "image", ImmutableMap.of(Configuration.getDefaultInstance(), "res/drawable/image1.jpg", locale("fr"), "res/drawable-fr/image1.jpg")).addFileResourceForMultipleConfigs("drawable", "image2", ImmutableMap.of(Configuration.getDefaultInstance(), "res/drawable/image2.jpg", locale("fr"), "res/drawable-fr/image2.jpg")).build();
ResourceTable featureResourceTable = new ResourceTableBuilder().addPackage("com.test.app.feature", 0x80).addFileResourceForMultipleConfigs("drawable", "image3", ImmutableMap.of(Configuration.getDefaultInstance(), "res/drawable/image3.jpg", locale("fr"), "res/drawable-fr/image3.jpg")).addFileResourceForMultipleConfigs("drawable", "image4", ImmutableMap.of(Configuration.getDefaultInstance(), "res/drawable/image4.jpg", locale("fr"), "res/drawable-fr/image4.jpg")).build();
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.addFile("dex/classes.dex").addFile("res/drawable/image1.jpg").addFile("res/drawable-fr/image1.jpg").addFile("res/drawable/image2.jpg").addFile("res/drawable-fr/image2.jpg").setManifest(androidManifest("com.test.app", withMinSdkVersion(14))).setResourceTable(baseResourceTable)).addModule("feature", builder -> builder.addFile("res/drawable/image3.jpg").addFile("res/drawable-fr/image3.jpg").addFile("res/drawable/image4.jpg").addFile("res/drawable-fr/image4.jpg").setManifest(androidManifest("com.test.app", withMinSdkVersion(14), withOnDemandDelivery(), withFusingAttribute(true), withTitle("@string/test_label", 0x7f010000))).setResourceTable(featureResourceTable)).setBundleConfig(BundleConfigBuilder.create().addResourcePinnedToMasterSplit(// image1 from "base" module
0x7f020000).addResourcePinnedToMasterSplit(// image4 from "feature" module
0x80010001).build()).build();
TestComponent.useTestModule(this, TestModule.builder().withAppBundle(appBundle).withOutputPath(outputFilePath).build());
buildApksManager.execute();
ZipFile apkSetFile = new ZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
// Verifying that standalone APKs contain all entries.
assertThat(standaloneApkVariants(result)).hasSize(1);
List<ApkSet> standaloneApkSets = standaloneApkVariants(result).get(0).getApkSetList();
assertThat(standaloneApkSets).hasSize(1);
List<ApkDescription> standaloneApkDescription = standaloneApkSets.get(0).getApkDescriptionList();
assertThat(standaloneApkDescription).hasSize(1);
File standaloneApkFile = extractFromApkSetFile(apkSetFile, standaloneApkDescription.get(0).getPath(), outputDir);
try (ZipFile standaloneZip = new ZipFile(standaloneApkFile)) {
assertThat(filesUnderPath(standaloneZip, ZipPath.create("res"))).containsExactly("res/drawable/image1.jpg", "res/drawable-fr/image1.jpg", "res/drawable/image2.jpg", "res/drawable-fr/image2.jpg", "res/drawable/image3.jpg", "res/drawable-fr/image3.jpg", "res/drawable/image4.jpg", "res/drawable-fr/image4.jpg", "res/xml/splits0.xml");
}
// Verifying split APKs.
assertThat(splitApkVariants(result)).hasSize(1);
List<ApkSet> splitApkSetList = splitApkVariants(result).get(0).getApkSetList();
Map<String, ApkSet> modules = Maps.uniqueIndex(splitApkSetList, apkSet -> apkSet.getModuleMetadata().getName());
assertThat(modules.keySet()).containsExactly("base", "feature");
List<ApkDescription> baseModuleApks = modules.get("base").getApkDescriptionList();
assertThat(baseModuleApks).hasSize(2);
Map<Boolean, ApkDescription> apkBaseMaster = Maps.uniqueIndex(baseModuleApks, apkDescription -> apkDescription.getSplitApkMetadata().getIsMasterSplit());
ApkDescription baseMaster = apkBaseMaster.get(/* isMasterSplit= */
true);
File baseMasterFile = extractFromApkSetFile(apkSetFile, baseMaster.getPath(), outputDir);
try (ZipFile baseMasterZip = new ZipFile(baseMasterFile)) {
assertThat(filesUnderPath(baseMasterZip, ZipPath.create("res"))).containsExactly("res/drawable/image1.jpg", "res/drawable-fr/image1.jpg", "res/drawable/image2.jpg", "res/xml/splits0.xml", "res/xml/locales_config.xml");
}
ApkDescription baseFr = apkBaseMaster.get(/* isMasterSplit= */
false);
File baseFrFile = extractFromApkSetFile(apkSetFile, baseFr.getPath(), outputDir);
try (ZipFile baseFrZip = new ZipFile(baseFrFile)) {
assertThat(filesUnderPath(baseFrZip, ZipPath.create("res"))).containsExactly("res/drawable-fr/image2.jpg");
}
List<ApkDescription> featureModuleApks = modules.get("feature").getApkDescriptionList();
assertThat(featureModuleApks).hasSize(2);
Map<Boolean, ApkDescription> apkFeatureMaster = Maps.uniqueIndex(featureModuleApks, apkDescription -> apkDescription.getSplitApkMetadata().getIsMasterSplit());
ApkDescription featureMaster = apkFeatureMaster.get(/* isMasterSplit= */
true);
File featureMasterFile = extractFromApkSetFile(apkSetFile, featureMaster.getPath(), outputDir);
try (ZipFile featureMasterZip = new ZipFile(featureMasterFile)) {
assertThat(filesUnderPath(featureMasterZip, ZipPath.create("res"))).containsExactly("res/drawable/image3.jpg", "res/drawable/image4.jpg", "res/drawable-fr/image4.jpg");
}
ApkDescription featureFr = apkFeatureMaster.get(/* isMasterSplit= */
false);
File featureFrFile = extractFromApkSetFile(apkSetFile, featureFr.getPath(), outputDir);
try (ZipFile featureFrZip = new ZipFile(featureFrFile)) {
assertThat(filesUnderPath(featureFrZip, ZipPath.create("res"))).containsExactly("res/drawable-fr/image3.jpg");
}
}
use of com.android.bundle.Commands.ApkSet in project bundletool by google.
the class ApkMatcherTest method apkMatch_withModuleTypeFiltering_splitApks_installTimeModules_deprecatedOnDemand.
@Test
public void apkMatch_withModuleTypeFiltering_splitApks_installTimeModules_deprecatedOnDemand() {
DeviceSpec device = deviceWithSdk(21);
ZipPath baseApk = ZipPath.create("master-base.apk");
ZipPath onDemandFeatureApk = ZipPath.create("master-feature1.apk");
ApkSet onDemandFeature = splitApkSet(/* moduleName= */
"onDemandFeature", DeliveryType.ON_DEMAND, /* moduleDependencies= */
ImmutableList.of(), splitApkDescription(ApkTargeting.getDefaultInstance(), onDemandFeatureApk));
ApkSet onDemandFeatureWithDeprecatedField = onDemandFeature.toBuilder().setModuleMetadata(onDemandFeature.getModuleMetadata().toBuilder().setOnDemandDeprecated(true)).build();
BuildApksResult buildApksResult = buildApksResult(/* bundletoolVersion= */
"0.10.0", createVariant(VariantTargeting.getDefaultInstance(), splitApkSet(/* moduleName= */
"base", splitApkDescription(ApkTargeting.getDefaultInstance(), baseApk)), onDemandFeatureWithDeprecatedField));
// By default only install-time module are matched.
Optional<ImmutableSet<String>> allModules = Optional.empty();
assertThat(createMatcher(device, allModules).getMatchingApks(buildApksResult)).containsExactly(baseMatchedApk(baseApk));
}
use of com.android.bundle.Commands.ApkSet 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.ApkSet in project bundletool by google.
the class BuildApksManagerTest method buildApksCommand_standalone_oneModuleManyVariants.
@Test
public void buildApksCommand_standalone_oneModuleManyVariants() 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"))).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).withOptimizationDimensions(ABI).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
ImmutableMap<Abi, Variant> standaloneVariantsByAbi = Maps.uniqueIndex(standaloneApkVariants(result), variant -> {
ApkDescription apkDescription = getOnlyElement(apkDescriptions(variant));
return getOnlyElement(apkDescription.getTargeting().getAbiTargeting().getValueList());
});
assertThat(standaloneVariantsByAbi.keySet()).containsExactly(toAbi(X86), toAbi(X86_64), toAbi(MIPS));
assertThat(standaloneVariantsByAbi.get(toAbi(X86)).getTargeting()).ignoringRepeatedFieldOrder().isEqualTo(mergeVariantTargeting(variantAbiTargeting(X86, ImmutableSet.of(X86_64, MIPS)), variantSdkTargeting(LOWEST_SDK_VERSION, ImmutableSet.of(L_SDK_VERSION, M_SDK_VERSION))));
assertThat(standaloneVariantsByAbi.get(toAbi(X86_64)).getTargeting()).ignoringRepeatedFieldOrder().isEqualTo(mergeVariantTargeting(variantAbiTargeting(X86_64, ImmutableSet.of(X86, MIPS)), variantSdkTargeting(LOWEST_SDK_VERSION, ImmutableSet.of(L_SDK_VERSION, M_SDK_VERSION))));
assertThat(standaloneVariantsByAbi.get(toAbi(MIPS)).getTargeting()).ignoringRepeatedFieldOrder().isEqualTo(mergeVariantTargeting(variantAbiTargeting(MIPS, ImmutableSet.of(X86, X86_64)), variantSdkTargeting(LOWEST_SDK_VERSION, ImmutableSet.of(L_SDK_VERSION, M_SDK_VERSION))));
for (Variant variant : standaloneVariantsByAbi.values()) {
assertThat(variant.getApkSetList()).hasSize(1);
ApkSet apkSet = variant.getApkSet(0);
assertThat(apkSet.getApkDescriptionList()).hasSize(1);
assertThat(apkSetFile).hasFile(apkSet.getApkDescription(0).getPath());
}
}
Aggregations