use of com.android.tools.build.bundletool.testing.AppBundleBuilder 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.tools.build.bundletool.testing.AppBundleBuilder 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.tools.build.bundletool.testing.AppBundleBuilder 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.tools.build.bundletool.testing.AppBundleBuilder 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");
}
use of com.android.tools.build.bundletool.testing.AppBundleBuilder in project bundletool by google.
the class BuildApksManagerTest method buildApksCommand_apkNotificationMessageKeyApexBundle_hasRightSuffix.
@Test
public void buildApksCommand_apkNotificationMessageKeyApexBundle_hasRightSuffix() throws Exception {
ApexImages apexConfig = apexImages(targetedApexImage("apex/x86_64.img", apexImageTargeting("x86_64")), targetedApexImage("apex/x86.img", apexImageTargeting("x86")), targetedApexImage("apex/arm64-v8a.img", apexImageTargeting("arm64-v8a")), targetedApexImage("apex/armeabi-v7a.img", apexImageTargeting("armeabi-v7a")), targetedApexImage("apex/arm64-v8a.armeabi-v7a.img", apexImageTargeting("arm64-v8a", "armeabi-v7a")));
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.addFile(APEX_MANIFEST_PATH, APEX_MANIFEST).addFile("apex/x86_64.img").addFile("apex/x86.img").addFile("apex/arm64-v8a.img").addFile("apex/armeabi-v7a.img").addFile("apex/arm64-v8a.armeabi-v7a.img").setApexConfig(apexConfig).setManifest(androidManifest("com.test.app"))).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).build());
buildApksManager.execute();
BuildApksResult result = extractTocFromApkSetFile(openZipFile(outputFilePath.toFile()), outputDir);
ImmutableList<Variant> variants = apexApkVariants(result);
ImmutableSet<String> apkPaths = variants.stream().map(variant -> getOnlyElement(getOnlyElement(variant.getApkSetList()).getApkDescriptionList()).getPath()).collect(toImmutableSet());
assertThat(apkPaths).containsExactly("standalones/standalone-x86_64.apex", "standalones/standalone-x86.apex", "standalones/standalone-arm64_v8a.apex", "standalones/standalone-armeabi_v7a.apex", "standalones/standalone-armeabi_v7a.arm64_v8a.apex");
}
Aggregations