use of com.android.bundle.Commands.Variant in project bundletool by google.
the class BuildApksManagerTest method buildApksCommand_standalone_textureTargetingWithSuffixStripped.
@Test
public void buildApksCommand_standalone_textureTargetingWithSuffixStripped() throws Exception {
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#tcf_atc/texture.dat").addFile("assets/textures#tcf_etc1/texture.dat").setAssetsConfig(assets(targetedAssetsDirectory("assets/textures#tcf_atc", assetsDirectoryTargeting(textureCompressionTargeting(ATC))), 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).withOptimizationDimensions(TEXTURE_COMPRESSION_FORMAT).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/textures/texture.dat");
assertThat(shardZip).doesNotHaveFile("assets/textures#tcf_atc/texture.dat");
assertThat(shardZip).doesNotHaveFile("assets/textures#tcf_etc1/texture.dat");
}
// Check that targeting was applied to both the APK and the variant
assertThat(standaloneApkVariants(result).get(0).getTargeting().getTextureCompressionFormatTargeting().getValueList()).containsExactly(textureCompressionFormat(ETC1_RGB8));
assertThat(shard.getTargeting().getTextureCompressionFormatTargeting().getValueList()).containsExactly(textureCompressionFormat(ETC1_RGB8));
}
use of com.android.bundle.Commands.Variant in project bundletool by google.
the class BuildApksManagerTest method splits_assetTextureCompressionFormatWithoutSuffixStripped.
@Test
public void splits_assetTextureCompressionFormatWithoutSuffixStripped() throws Exception {
Path bundlePath = createAppBundleWithBaseModuleWithTextureTargeting(/* tcfSplittingEnabled= */
true, /* stripTargetingSuffixEnabled= */
false);
TestComponent.useTestModule(this, createTestModuleBuilder().withBundlePath(bundlePath).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(1);
ImmutableList<ApkDescription> tcfSplits = splitApks.stream().filter(apkDesc -> apkDesc.getTargeting().hasTextureCompressionFormatTargeting()).collect(toImmutableList());
assertThat(apkNamesInApkDescriptions(tcfSplits)).containsExactly("base-atc.apk", "base-etc1_rgb8.apk");
for (ApkDescription split : tcfSplits) {
TextureCompressionFormatTargeting textureFormatTargeting = split.getTargeting().getTextureCompressionFormatTargeting();
assertThat(textureFormatTargeting.getValueList()).hasSize(1);
TextureCompressionFormat format = textureFormatTargeting.getValueList().get(0);
Set<String> files = filesInApk(split, apkSetFile);
switch(format.getAlias()) {
case ATC:
assertThat(files).contains("assets/textures#tcf_atc/texture.dat");
break;
case ETC1_RGB8:
assertThat(files).contains("assets/textures#tcf_etc1/texture.dat");
break;
default:
fail("Unexpected texture compression format");
}
}
}
use of com.android.bundle.Commands.Variant in project bundletool by google.
the class BuildApksManagerTest method buildApksCommand_universal_mergeActivitiesFromFeatureManifest_0_13_4.
@Test
public void buildApksCommand_universal_mergeActivitiesFromFeatureManifest_0_13_4() throws Exception {
final int baseThemeRefId = 123;
final int featureThemeRefId = 4456;
AppBundle appBundle = new AppBundleBuilder().setBundleConfig(BundleConfig.newBuilder().setBundletool(Bundletool.newBuilder().setVersion("0.13.4")).build()).addModule("base", builder -> builder.setManifest(androidManifest("com.test.app", withCustomThemeActivity("activity1", baseThemeRefId), withCustomThemeActivity("activity2", baseThemeRefId))).setResourceTable(resourceTableWithTestLabel("Test feature"))).addModule("feature", builder -> builder.setManifest(androidManifestForFeature("com.test.app.feature1", withFusingAttribute(true), withTitle("@string/test_label", TEST_LABEL_RESOURCE_ID), withCustomThemeActivity("activity1", featureThemeRefId), withSplitNameService("service1", "feature")))).addModule("not_fused", builder -> builder.setManifest(androidManifestForFeature("com.test.app.feature2", withFusingAttribute(false), withTitle("@string/test_label", TEST_LABEL_RESOURCE_ID), withCustomThemeActivity("activity2", featureThemeRefId), withSplitNameService("service2", "not_fused")))).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).withApkBuildMode(UNIVERSAL).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
Variant universalVariant = standaloneApkVariants(result).get(0);
assertThat(apkDescriptions(universalVariant)).hasSize(1);
ApkDescription universalApk = apkDescriptions(universalVariant).get(0);
// Correct modules selected for merging.
assertThat(universalApk.getStandaloneApkMetadata().getFusedModuleNameList()).containsExactly("base", "feature");
File universalApkFile = extractFromApkSetFile(apkSetFile, universalApk.getPath(), outputDir);
AndroidManifest manifest = extractAndroidManifest(universalApkFile, tmpDir);
Map<String, Integer> refIdByActivity = transformValues(manifest.getActivitiesByName(), activity -> activity.getAndroidAttribute(AndroidManifest.THEME_RESOURCE_ID).get().getValueAsRefId());
assertThat(refIdByActivity).containsExactly("activity1", featureThemeRefId, "activity2", baseThemeRefId);
assertThat(getServicesFromManifest(manifest)).isEmpty();
}
use of com.android.bundle.Commands.Variant in project bundletool by google.
the class BuildApksManagerTest method splits_assetTextureCompressionFormatWithSuffixStripped.
@Test
public void splits_assetTextureCompressionFormatWithSuffixStripped() throws Exception {
Path bundlePath = createAppBundleWithBaseModuleWithTextureTargeting(/* tcfSplittingEnabled= */
true, /* stripTargetingSuffixEnabled= */
true);
TestComponent.useTestModule(this, createTestModuleBuilder().withBundlePath(bundlePath).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(1);
ImmutableList<ApkDescription> tcfSplits = splitApks.stream().filter(apkDesc -> apkDesc.getTargeting().hasTextureCompressionFormatTargeting()).collect(toImmutableList());
assertThat(apkNamesInApkDescriptions(tcfSplits)).containsExactly("base-atc.apk", "base-etc1_rgb8.apk");
for (ApkDescription split : tcfSplits) {
TextureCompressionFormatTargeting textureFormatTargeting = split.getTargeting().getTextureCompressionFormatTargeting();
assertThat(textureFormatTargeting.getValueList()).hasSize(1);
TextureCompressionFormat format = textureFormatTargeting.getValueList().get(0);
Set<String> files = filesInApk(split, apkSetFile);
switch(format.getAlias()) {
case ATC:
assertThat(files).contains("assets/textures/texture.dat");
break;
case ETC1_RGB8:
assertThat(files).contains("assets/textures/texture.dat");
break;
default:
fail("Unexpected texture compression format");
}
}
}
use of com.android.bundle.Commands.Variant 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()));
}
Aggregations