use of com.android.bundle.Commands.BuildApksResult 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.BuildApksResult in project bundletool by google.
the class BuildApksManagerTest method splits_assetMixedTextureTargetingWithSuffixStripped_featureModule.
@Test
public void splits_assetMixedTextureTargetingWithSuffixStripped_featureModule() throws Exception {
// Create a bundle with assets containing both ETC1 textures and textures without
// targeting specified.
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.setManifest(androidManifest("com.test.app")).setResourceTable(resourceTableWithTestLabel("Test feature"))).addModule("feature_tcf_assets", builder -> builder.addFile("assets/textures/untargeted_texture.dat").addFile("assets/textures#tcf_etc1/etc1_texture.dat").setAssetsConfig(assets(targetedAssetsDirectory("assets/textures", assetsDirectoryTargeting(alternativeTextureCompressionTargeting(ETC1_RGB8))), targetedAssetsDirectory("assets/textures#tcf_etc1", assetsDirectoryTargeting(textureCompressionTargeting(ETC1_RGB8))))).setManifest(androidManifestForFeature("com.test.app", withTitle("@string/test_label", TEST_LABEL_RESOURCE_ID)))).setBundleConfig(BundleConfigBuilder.create().addSplitDimension(Value.TEXTURE_COMPRESSION_FORMAT, /* negate= */
false, /* stripSuffix= */
true, /* defaultSuffix= */
"etc1").build()).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
ImmutableList<Variant> splitApkVariants = splitApkVariants(result);
ImmutableList<ApkDescription> splitApks = apkDescriptions(splitApkVariants);
assertThat(splitApkVariants(result)).hasSize(1);
Variant splitApkVariant = splitApkVariants(result).get(0);
assertThat(splitApkVariant.getApkSetList()).hasSize(2);
// Check that apks for ETC1 and "Other TCF" have been created
ImmutableList<ApkDescription> tcfSplits = splitApks.stream().filter(apkDesc -> apkDesc.getTargeting().hasTextureCompressionFormatTargeting()).collect(toImmutableList());
assertThat(apkNamesInApkDescriptions(tcfSplits)).containsExactly("feature_tcf_assets-other_tcf.apk", "feature_tcf_assets-etc1_rgb8.apk");
// Check the content of the apks
for (ApkDescription split : tcfSplits) {
TextureCompressionFormatTargeting textureFormatTargeting = split.getTargeting().getTextureCompressionFormatTargeting();
Set<String> files = filesInApk(split, apkSetFile);
if (textureFormatTargeting.getValueList().isEmpty()) {
// The "Other TCF" split contains the untargeted texture only.
assertThat(files).contains("assets/textures/untargeted_texture.dat");
assertThat(files).doesNotContain("assets/textures#tcf_etc1/etc1_texture.dat");
} else {
// The "ETC1" split contains the ETC1 texture only.
TextureCompressionFormat format = textureFormatTargeting.getValueList().get(0);
assertThat(format.getAlias()).isEqualTo(ETC1_RGB8);
// Suffix stripping was enabled, so "textures#tcf_etc1" folder is now renamed to "textures".
assertThat(files).contains("assets/textures/etc1_texture.dat");
assertThat(files).doesNotContain("assets/textures#tcf_etc1/etc1_texture.dat");
assertThat(files).doesNotContain("assets/textures/untargeted_texture.dat");
}
}
}
use of com.android.bundle.Commands.BuildApksResult in project bundletool by google.
the class BuildApksManagerTest method buildApksCommand_standalone_deviceTierTargetingWithSuffixStripped.
@Test
public void buildApksCommand_standalone_deviceTierTargetingWithSuffixStripped() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.setManifest(androidManifest("com.test.app")).setResourceTable(resourceTableWithTestLabel("Test feature"))).addModule("device_tier_assets", builder -> builder.addFile("assets/img#tier_0/asset_low.dat").addFile("assets/img#tier_1/asset_high.dat").setAssetsConfig(assets(targetedAssetsDirectory("assets/img#tier_0", assetsDirectoryTargeting(deviceTierTargeting(0))), targetedAssetsDirectory("assets/img#tier_1", assetsDirectoryTargeting(deviceTierTargeting(1))))).setManifest(androidManifestForAssetModule("com.test.app", withInstallTimeDelivery()))).setBundleConfig(BundleConfigBuilder.create().addSplitDimension(Value.DEVICE_TIER, /* negate= */
false, /* stripSuffix= */
true, /* defaultSuffix= */
"0").build()).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
assertThat(standaloneApkVariants(result)).hasSize(1);
assertThat(apkDescriptions(standaloneApkVariants(result))).hasSize(1);
ApkDescription shard = apkDescriptions(standaloneApkVariants(result)).get(0);
// Check APK content
assertThat(apkSetFile).hasFile(shard.getPath());
try (ZipFile shardZip = new ZipFile(extractFromApkSetFile(apkSetFile, shard.getPath(), outputDir))) {
assertThat(shardZip).hasFile("assets/img/asset_low.dat");
assertThat(shardZip).doesNotHaveFile("assets/img/asset_high.dat");
assertThat(shardZip).doesNotHaveFile("assets/img#tier_0/asset_low.dat");
assertThat(shardZip).doesNotHaveFile("assets/img#tier_1/asset_high.dat");
}
// Check that default device tier targeting was applied to the APK
assertThat(shard.getTargeting().getDeviceTierTargeting().getValueList()).containsExactly(Int32Value.of(0));
}
use of com.android.bundle.Commands.BuildApksResult in project bundletool by google.
the class BuildApksManagerTest method selectsRightModules_systemApks.
@Test
@Theory
public void selectsRightModules_systemApks() 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).withApkBuildMode(SYSTEM).withDeviceSpec(mergeSpecs(sdkVersion(28), abis("x86"), density(DensityAlias.MDPI), locales("en-US"))).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
// System APKs: Only base and modules marked for fusing must be used.
assertThat(systemApkVariants(result)).hasSize(1);
ImmutableList<ApkDescription> systemApks = apkDescriptions(systemApkVariants(result));
assertThat(systemApks).containsExactly(ApkDescription.newBuilder().setPath("system/system.apk").setTargeting(ApkTargeting.getDefaultInstance()).setSystemApkMetadata(SystemApkMetadata.newBuilder().addAllFusedModuleName(ImmutableList.of("base", "fused"))).build(), ApkDescription.newBuilder().setPath("splits/not_fused-master.apk").setTargeting(ApkTargeting.getDefaultInstance()).setSplitApkMetadata(SplitApkMetadata.newBuilder().setSplitId("not_fused").setIsMasterSplit(true)).build());
File systemApkFile = extractFromApkSetFile(apkSetFile, "system/system.apk", outputDir);
// Validate that the system APK contains appropriate files.
ZipFile systemApkZip = openZipFile(systemApkFile);
assertThat(filesUnderPath(systemApkZip, ZipPath.create("assets"))).containsExactly("assets/base.txt", "assets/fused.txt");
}
use of com.android.bundle.Commands.BuildApksResult in project bundletool by google.
the class BuildApksManagerTest method deviceTieredAssets_inAssetModule.
@Test
public void deviceTieredAssets_inAssetModule() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.setManifest(androidManifest("com.test.app"))).addModule("assetmodule", builder -> builder.addFile("assets/images#tier_0/image.jpg").addFile("assets/images#tier_1/image.jpg").setManifest(androidManifestForAssetModule("com.test.app")).setAssetsConfig(assets(targetedAssetsDirectory("assets/images#tier_0", assetsDirectoryTargeting(deviceTierTargeting(/* value= */
0, /* alternatives= */
ImmutableList.of(1)))), targetedAssetsDirectory("assets/images#tier_1", assetsDirectoryTargeting(deviceTierTargeting(/* value= */
1, /* alternatives= */
ImmutableList.of(0))))))).setBundleConfig(BundleConfigBuilder.create().addSplitDimension(Value.DEVICE_TIER, /* negate= */
false, /* stripSuffix= */
false, /* defaultSuffix= */
"0").build()).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
assertThat(result.getAssetSliceSetList()).hasSize(1);
List<ApkDescription> assetSlices = result.getAssetSliceSet(0).getApkDescriptionList();
// Check that apks for tier 0 and 1 have been created
ImmutableList<ApkDescription> deviceTierSplits = assetSlices.stream().filter(apkDesc -> apkDesc.getTargeting().hasDeviceTierTargeting()).collect(toImmutableList());
assertThat(apkNamesInApkDescriptions(deviceTierSplits)).containsExactly("assetmodule-tier_0.apk", "assetmodule-tier_1.apk");
// Check the content of the APKs
ImmutableMap<DeviceTierTargeting, ApkDescription> deviceTierSplitsByTargeting = Maps.uniqueIndex(deviceTierSplits, apk -> apk.getTargeting().getDeviceTierTargeting());
ApkDescription lowTierSplit = deviceTierSplitsByTargeting.get(deviceTierTargeting(/* value= */
0, /* alternatives= */
ImmutableList.of(1)));
assertThat(ZipPath.create(lowTierSplit.getPath()).getFileName().toString()).isEqualTo("assetmodule-tier_0.apk");
assertThat(filesInApk(lowTierSplit, apkSetFile)).contains("assets/images#tier_0/image.jpg");
ApkDescription mediumTierSplit = deviceTierSplitsByTargeting.get(deviceTierTargeting(/* value= */
1, /* alternatives= */
ImmutableList.of(0)));
assertThat(ZipPath.create(mediumTierSplit.getPath()).getFileName().toString()).isEqualTo("assetmodule-tier_1.apk");
assertThat(filesInApk(mediumTierSplit, apkSetFile)).contains("assets/images#tier_1/image.jpg");
}
Aggregations