use of com.android.bundle.Commands.BuildApksResult 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.BuildApksResult in project bundletool by google.
the class BuildApksManagerTest method firstVariantNumber.
@Test
public void firstVariantNumber() throws Exception {
final int firstVariantNumber = 100;
TestComponent.useTestModule(this, createTestModuleBuilder().withFirstVariantNumber(100).withOutputPath(outputFilePath).build());
buildApksManager.execute();
BuildApksResult buildApksResult = ApkSetUtils.extractTocFromApkSetFile(openZipFile(outputFilePath.toFile()), outputDir);
// This test is only interesting if there is more than one variant (though we don't care about
// the exact number).
assertThat(buildApksResult.getVariantCount()).isGreaterThan(1);
int expectedVariantNumber = firstVariantNumber;
for (Variant variant : buildApksResult.getVariantList()) {
assertThat(variant.getVariantNumber()).isEqualTo(expectedVariantNumber);
expectedVariantNumber++;
}
}
use of com.android.bundle.Commands.BuildApksResult in project bundletool by google.
the class BuildApksManagerTest method buildApksCommand_universal_generatesSingleApkWithSingleFallbackTcf.
@Test
public void buildApksCommand_universal_generatesSingleApkWithSingleFallbackTcf() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.setManifest(androidManifest("com.test.app"))).addModule("tcf_assets", builder -> builder.addFile("assets/textures/fallback_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(androidManifestForAssetModule("com.test.app", withInstallTimeDelivery()))).setBundleConfig(BundleConfigBuilder.create().addSplitDimension(Value.TEXTURE_COMPRESSION_FORMAT).build()).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).withApkBuildMode(UNIVERSAL).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
assertThat(standaloneApkVariants(result)).hasSize(1);
Variant universalVariant = standaloneApkVariants(result).get(0);
assertThat(apkDescriptions(universalVariant)).hasSize(1);
ApkDescription universalApk = apkDescriptions(universalVariant).get(0);
// Check APK content
File universalApkFile = extractFromApkSetFile(apkSetFile, universalApk.getPath(), outputDir);
try (ZipFile universalApkZipFile = new ZipFile(universalApkFile)) {
// Only the requested format texture is included in the standalone APK.
// Even if suffix stripping is not activated, the universal APK must only contain one TCF.
assertThat(filesUnderPath(universalApkZipFile, ASSETS_DIRECTORY)).containsExactly("assets/textures/fallback_texture.dat");
}
}
use of com.android.bundle.Commands.BuildApksResult 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();
}
use of com.android.bundle.Commands.BuildApksResult in project bundletool by google.
the class BuildApksManagerTest method buildApksCommand_standalone_mixedTextureTargeting.
@Test
public void buildApksCommand_standalone_mixedTextureTargeting() 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/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).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))) {
// Only the default format texture is included in the standalone APK.
// Even if suffix stripping is not activated, the standalone APK must only contain one TCF.
assertThat(shardZip).hasFile("assets/textures/untargeted_texture.dat");
assertThat(shardZip).doesNotHaveFile("assets/textures#tcf_etc1/texture.dat");
}
}
Aggregations